class Wire private boolean value public boolean get
〔プログラム〕 class Wire { private boolean value; public boolean get. Value() { return value; } public void set. Value(boolean value) { this. value = value; } } abstract class Gate { protected Wire[] input; protected Wire output; public Gate(int n. Inputs) { a input = ; for (int i = 0; i < n. Inputs; i++) { input[i] = new Wire(); } output = new Wire(); }
public void connect. Output. To(Gate other. Gate, int nth. Input) { try { ; b } catch (Exception e) { e. print. Stack. Trace(); } } public Wire get. Input(int n) { return input[n]; } public Wire get. Output() { return output; } abstract public void tick(); }
class Not. Gate extends Gate { public Not. Gate() { super(1); } c ); } public void tick() { output. set. Value( } class And. Gate extends Gate { public And. Gate() { super(2); } d ); } public void tick() { output. set. Value( } public class Logic. Circuit. Test { public static void main(String[] args) { Gate not = new Not. Gate(); Gate and = new And. Gate(); not. connect. Output. To(and, 0); not. get. Input(0). set. Value(false); and. get. Input(1). set. Value(true); not. tick(); and. tick(); System. out. println(and. get. Output(). get. Value()); } }
設問 プログラム中の に入れる正しい答えを,解答群の中か ら選べ。 a に関する解答群 ア new Wire(n. Inputs) イ new Wire[n. Inputs] ウ new Wire() エ new Wire[] {new Wire()} b に関する解答群 ア input[nth. Input]. set. Value(other. Gate. output. get. Value()) イ input[nth. Input] = other. Gate. output ウ other. Gate. input[nth. Input]. set. Value(output. get. Value()) エ other. Gate. input[nth. Input] = output
c,d に関する解答群 ア input[0]. get. Value() || input[1]. get. Value() イ !input[0]. get. Value() || !input[1]. get. Value() ウ input[0]. get. Value() && input[1]. get. Value() エ !input[0]. get. Value() && !input[1]. get. Value() オ input[0]. get. Value() != input[1]. get. Value() カ input[0]. get. Value() キ !input[0]. get. Value() ク 1 - input[0]. get. Value()
〔プログラム 1〕 public class Area. Test { public static void main(String args[]) { Figure[] figures = { new Triangle(2, 3, 3), new Rectangle(5, 8), new Square(5)}; for (int i = 0; i < figures. length; i++) { System. out. println(figures[i] + "area = " + figures[i]. get. Area()); } } } 〔プログラム 2〕 public abstract class Figure { public abstract double get. Area(); }
〔プログラム 3〕 a public class Triangle extends { double la; double lb; double lc; public Triangle(double la, double lb, double lc) { this. la = la; this. lb = lb; this. lc = lc; } public String to. String() { return "Triangle : sides = " + la + ", " + lb + ", " + lc + " : "; } public double get. Area() { double s = (la + lb + lc) / 2. 0; return Math. sqrt(s * (s - la) * (s - lb) * (s - lc)); } }
〔プログラム 4〕 public class Rectangle extends b { double height; double width; public Rectangle(double height, double width) { this. height = height; this. width = width; } public String to. String() { return "Rectangle : height = " + height + ", width = " + width + " : "; } public double get. Area() { return } } c ;
〔プログラム 5〕 public class Square extends { d public Square(double width) { ; e } public String to. String() { return "Square : width = " + width + " : "; } }
設問 プログラム中の に入れる正しい答えを,解答群の中から選べ。解答 は,重複して選んでもよい。 a,b,d に関する解答群 ア abstract イ Figure ウ get. Area エ Rectangle オ Square カ super c に関する解答群 ア height イ height * height ウ height * width エ width オ width * width e に関する解答群 ア super(height) イ super(height, height) ウ super(width) エ super(width, height) オ super(width, width) カ this. height = height キ this. height = width ク this. width = height ケ this. width = width
- Slides: 24