I java 065762A 19.6.22 19.6.22 19.6.22 1
1 Level 1 3 1.1 Kouza....................................... 3 1.2 Kouza....................................... 4 1.3.......................................... 4 2 Level 2 4 2.1 Kouza....................................... 5 2.2 Test........................................ 5 2.3.......................................... 5 3 Level 3 5 3.1 Test........................................ 5 3.2 Shape....................................... 6 3.3 Triangle...................................... 6 3.4 Circle....................................... 6 3.5.......................................... 7 4 Level 4 7 4.1 Square....................................... 7 4.2 Test........................................ 7 4.3.......................................... 7 5 Level 5 8 5.1 CaBase...................................... 8 5.2 CaTester...................................... 10 6 Level 5-2 11 6.1 CaLeft....................................... 11 6.2 CaTester...................................... 11 6.3.......................................... 11 7 Level 6 12 7.1 CaTester...................................... 12 7.2 ic2.txt........................................... 13 7.3.......................................... 13 2
1 Level 1 1 1.1 Kouza class Kouza int number; // int zandaka; // public Kouza(int x) // number = x; //number zandaka = 0; //zandaka 0 public void azuke(int in) //azuke printnum(); //printnum zandaka += in; //zandaka System.out.print(in + " in\t");// public int hikidashi(int out) //hikidashi int hiki; // printnum(); //printnum if(zandaka>=out) zandaka -= out; hiki = out; else // hiki=zandaka; // zandaka = 0; return(hiki); //hiki private void printnum()// number System.out.print("Kouza" + number + ":\t"); public void printzan() //zandaka System.out.println("zandaka:" + zandaka); 3
1.2 Kouza Test import java.io.*; class Test public static void main(string args[]) //main Kouza kouza1 = new Kouza(1234); //Kouza kouza1 // 1234 number( ) Kouza kouza2 = new Kouza(1235); kouza1.azuke(100); //kouza1 azuke kouza1.printzan(); //kouza1 printzan kouza2.azuke(200); kouza2.printzan(); System.out.print(new Integer(kouza1.hikidashi(50)).toString() + " out\t"); //kouza1 hikidashi kouza1.printzan(); //kouza1 printzan System.out.print(new Integer(kouza1.hikidashi(100)).toString() + " out\t"); kouza1.printzan(); System.out.print(new Integer(kouza2.hikidashi(3000)).toString() + " out\t"); kouza2.printzan(); 1.3 % java Test Kouza1234: 100 in zandaka:100 Kouza1235: 200 in zandaka:200 Kouza1234: 50 out zandaka:50 Kouza1234: 50 out zandaka:0 Kouza1235: 200 out zandaka:0 kouza1234 100 kouza1235 200 kouza1234 50 kouza1234 100 50 50 kouza1235 3000 200 200 2 Level 2 2 4
2.1 Kouza private int number; private int zandaka; Test zandaka 2.2 Test kouza1.zandaka = 1000; 2.3 % javac *.java test.java:8: zandaka Kouza private kouza1.zandaka = 1000; ^ 1 private 3 Level 3 3 3.1 Test class Test public static void main(string args[]) //main Shape shape1 = new Triangle(5); //Triangle shape1 Shape shape2 = new Circle(4); shape1.draw(); //shape1 draw shape2.draw(); 5
3.2 Shape abstract class Shape // Shape public Shape() // abstract public void draw(); // draw // // 3.3 Triangle import java.io.*; class Triangle extends Shape //Shape Triangle double msize; //double msize public Triangle(int size) // msize = size; // msize public void draw() //draw System.out.println("Drawing a triangle of size " +new Double(mSize).toString()); 3.4 Circle class Circle extends Shape //Shape Circle double mradius; //double mradius public Circle(int r) // mradius = r; // mradius public void draw() //draw System.out.println("Drawing a Circle of radius " + new Double(mRadius).toString()); 6
3.5 % java Test Drawing a triangle of size 5.0 Drawing a Circle of radius 4.0 4 Level 4 4.1 Square class Square extends Shape //Shape Square double msize; //double msize public Square(int size)// msize = size; public void draw() System.out.println("Drawing a square of size " + new Double(mSize).toString()); 4.2 Test class Test public static void main(string args[]) Shape shape1 = new Triangle(5); Shape shape2 = new Circle(4); Shape shape3 = new Square(3); //Square shape3 shape1.draw(); shape2.draw(); shape3.draw(); //Shape3 draw 4.3 % java Test 7
Drawing a triangle of size 5.0 Drawing a Circle of radius 4.0 Drawing a square of size 3.0 5 Level 5 4 5.1 CaBase /* 1CA 2007/6/2 Y. Akamine */ import java.io.*; class CaBase int mnumcells; // int[] mwritebuf; // int[] mreadbuf; public CaBase(int ncells) // mnumcells = ncells; mwritebuf = new int[ncells]; //mwritebuf ncells mreadbuf = new int[ncells]; // public boolean readic(string ic_filename) try BufferedReader reader = new BufferedReader(new FileReader(ic_filename)); //ic_filename reader String str = reader.readline(); // reader String str int i; // // 0 8
for(i=0; i<mnumcells; ++i) if(i < str.length() ) if(str.charat(i) == 0 ) writestate(i, 0); else writestate(i, 1); else writestate(i, 0); catch(filenotfoundexception e) //ic_filename System.err.println(" " + ic_filename); return false; catch(exception e) // System.err.println(e); return false; swapbuffers(); //swapbuffers return true; int i; // public void updateca() // i-1,i,i+1 for(i=0; i<mnumcells; ++i) writestate(i, transfunc(readstate(i-1), readstate(i), readstate(i+1))); swapbuffers(); // public void printstatus() int i; for(i=0; i<mnumcells; ++i) System.out.print(new Integer(readState(i)).toString()); System.out.print( \n ); 9
// // protected protected int transfunc(int l, int c, int r) return (l+c+r) == 1? 1 : 0; // private // private int calcposition(int x) return (x+mnumcells) % mnumcells; // mwritebuf private void writestate(int x, int s) mwritebuf[calcposition(x)] = s; // sreadbuf private int readstate(int x) return mreadbuf[calcposition(x)]; // private void swapbuffers() int[] temp = mreadbuf; mreadbuf = mwritebuf; mwritebuf = temp; 5.2 CaTester class CaTester public static void main(string args[]) CaBase ca = new CaBase(8); // 8 ca // CaLeft ca = new CaLeft(8); //level4-2 ca.readic("ic.txt"); // ic.txt 10
int i; for(i=0; i!=8; ++i) ca.updateca(); ca.printstatus(); 6 Level 5-2 CaBase 6.1 CaLeft class CaLeft extends CaBase //CaBase CaLeft public CaLeft(int ncells) super(ncells); // //transfunc public int transfunc(int l, int c, int r) return(l+c+r) == 0? 1 : 0; java super(ncells) 6.2 CaTester //CaBase ca = new CaBase(8); CaLeft ca = new CaLeft(8); 6.3 % java CaTester 11
7 Level 6 level4,5 CaBase ( ) ( 1.2( 2) ) CaTester ca ca2 7.1 CaTester class CaTester public static void main(string args[]) // CaBase ca = new CaBase(8); CaLeft ca = new CaLeft(8); CaLeft ca2 = new CaLeft(8); //ca2 ca.readic("ic.txt"); int i; for(i=0; i!=8; ++i) ca.updateca(); ca.printstatus(); System.out.println( \n ); // ca2.readic("ic2.txt"); //ic2.txt for(i=0; i!=8; ++i) //ca2 ca2.updateca(); ca2.printstatus(); ic2.txt ca2 12
7.2 ic2.txt 00110011 7.3 % java CaTester 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111 2 ca2 [1] java http://www.ie.u-ryukyu.ac.jp/ e065762/ [2] java http://www.nextindex.net/java/ 13