Thursday, June 23, 2011

Calculator OOP 2 Debug

import java.util.Scanner;
class Calc3{
public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
Scanner in = new Scanner(System.in);
double val1 = in.nextDouble();
char sign = in.next().charAt(0);
double dun;
String className = null;
switch(sign){
case '+':
//Nemeh o1 = new Nemeh();
className = "Nemeh";
break;
case '-':
//Hasah o1 = new Hasah();
className = "Hasah";
break;
case 'y':
//Yazguur o1 = new Yazguur();
className = "Yazguur";
break;
}
Uildel o1 = (Uildel) Class.forName(className).newInstance();
o1.setVal1(val1);
o1.input();
o1.action();
o1.display();
}
abstract class Uildel{
protected double val1, val2, dun;
public void setVal1(double val1){
this.val1 = val1;
}
char temdeg;
int args = 2;
abstract public void action();
public void display(){
System.out.println(val1+" "+temdeg+" "+val2+" = "+dun);
}
public void input(){
if(args == 2){
Scanner in = new Scanner(System.in);
this.val2 = in.nextDouble();
}
}
}
class Nemeh extends Uildel{
public Nemeh(){
this.temdeg = '+';
}
public void action(){
this.dun = val1 + val2;
}
}
class Hasah extends Uildel{
public Hasah(){
temdeg = '+';
}
public void action(){
this.dun = val1 - val2;
}
}
class Yazguur extends Uildel{
public Yazguur(){
temdeg = 'y';
args = 1;
}
public void action(){
this.dun = Math.sqrt(val1);
}
}
}

No comments:

Post a Comment