Yurttas/PL/OOL/Java/F/05/02/05/00/il/IntegerList.java

From ZCubes Wiki
Revision as of 14:48, 7 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="java" line start="1" enclose="div">/** * Copyright(C) 1998 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. * * P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
  1/**
  2 *  Copyright(C) 1998
  3 *  All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4 *
  5 *  Permission to use, copy, modify, and distribute this
  6 *  software and its documentation for EDUCATIONAL purposes
  7 *  and without fee is hereby granted provided that this
  8 *  copyright notice appears in all copies.
  9 *
 10 *  @date   : January 1, 1998.
 11 *  @author : Salih Yurttas.
 12 */
 13
 14
 15package il;
 16
 17import java.io.*;
 18
 19public class IntegerList {
 20
 21  static final int N = 16;
 22
 23  private int[] list;
 24  private int count=0;
 25
 26  public IntegerList() {
 27    list = new int[N];
 28
 29    for (int i=0; i<N; i++)
 30      list[i] = 0;
 31  }
 32
 33  public IntegerList(final int size) {
 34    list = new int[size];
 35
 36    for (int i=0; i<size; i++)
 37      list[i] = 0;
 38  }
 39
 40  public IntegerList(final IntegerList l) {
 41    int size = l.length();
 42    list = new int[size];
 43    count = l.count;
 44
 45    for (int i=0; i<size; i++)
 46      list[i] = l.list[i];
 47  }
 48
 49  public int length() {
 50    return list.length;
 51  }
 52
 53  public int size() {
 54    return count;
 55  }
 56
 57  public int getIntegerAt(final int i) {
 58    return list[i];
 59  }
 60
 61  public void setIntegerAt(final int i,
 62                           final int value) {
 63    list[i] = value;
 64  }
 65
 66  public void getIntegerList ()
 67    throws IOException
 68  {
 69    DataInputStream dInS = new DataInputStream(System.in);
 70    Reader kR = new BufferedReader(new InputStreamReader(dInS));
 71    StreamTokenizer kTokens = new StreamTokenizer(kR);
 72
 73    System.out.print("inFileName : ");
 74    System.out.flush();
 75    kTokens.nextToken();
 76    String inFileName = kTokens.sval;
 77
 78    FileInputStream fInS = new FileInputStream(inFileName);
 79    Reader fR = new BufferedReader(new InputStreamReader(fInS));
 80    StreamTokenizer fTokens = new StreamTokenizer(fR);
 81
 82    while(fTokens.nextToken() != fTokens.TT_EOF)
 83      list[count++] = (int) fTokens.nval;
 84  }
 85
 86  public void putIntegerList ()
 87    throws IOException
 88  {
 89    DataInputStream dInS = new DataInputStream(System.in);
 90    Reader kR = new BufferedReader(new InputStreamReader(dInS));
 91    StreamTokenizer kTokens = new StreamTokenizer(kR);
 92
 93    System.out.print("outFileName : ");
 94    System.out.flush();
 95    kTokens.nextToken();
 96    String outFileName = kTokens.sval;
 97
 98    FileOutputStream fOutS = new FileOutputStream(outFileName);
 99    PrintWriter pOutL = new PrintWriter(fOutS);
100
101    int size = count;
102
103    for (int i=0; i<size; i++) 
104      pOutL.println(list[i]);
105
106    pOutL.close();
107  }
108
109}