import java.util.*; --8번 class Point{ private int x,y; public Point(int x,int y) { this.x =x; this.y =y; } public int getX() { if(x>0) { return x; } else { return 0; } } public int getY() { if(y>0) { return y; } else { return 0; } } protected void move(int x,int y) { this.x=x; this.y=y; } } class PositivePoint extends Point{ int z; PositivePoint() { super(0,0); } PositivePoint(int x,int y) { super(x,y); } protected void move(int x,int y) { move(x,y); } public String toString() { return "("+getX()+","+getY()+")의 점"; } } public class Main{ public static void main(String[] args) { PositivePoint p=new PositivePoint(); p.move(10,10); System.out.println(p.toString()+"입니다."); p.move(10,10); System.out.println(p.toString()+"입니다."); PositivePoint p2=new PositivePoint(-10,-10); System.out.println(p2.toString()+"입니다."); } }
---- import java.util.*; 11번 class A{ int a,b; A() { this.a=0; this.b=0; } protected int getA(int f) { return f; } protected void SetValue(int a,int b) { this.a=a; this.b=b; } protected int calculate(String c) { return c.charAt(0); } } class Add extends A{ protected void add() { getA(a+b); } } class Sub extends A{ protected int add(int a,int b) { return a-b; } } class Mul extends A{ protected int add(int a,int b) { return a*b; } } class Div extends A{ protected int add(int a,int b) { return a/b; } } public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("두 정수와 연산자를 입력하시오>>"); int a=sc.nextInt(); int b=sc.nextInt(); String c=sc.next(); A B=new A(); B.SetValue(a,b); if(B.calculate(c)=="+") } }