Sunday, June 26, 2011

CS211 - 70 onoo

Доорх холбоос дээр дарж дүнгээ үзнэ үү. Дүнгийн асуудалтай гэж үзвэл 6-р сарын 28-нд 17 цагт бахдан уулзаж асуудалаа шийдвэрлэнэ үү. https://spreadsheets.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Agy8N34zEKcudEdPOGFFbk1CcGpwQk1aZlphMHFpTnc&output=html

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);
}
}
}

Sunday, June 19, 2011

Calculator OOP

import java.util.Scanner;
public class Calculator{
private double val1;
private double val2;
private char sign;

public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
Scanner in = new Scanner(System.in);
Calculator calc = new Calculator();
calc.val1 = in.nextDouble();
calc.sign = in.next().charAt(0);
calc.val2 = in.nextDouble();

String className = Controller.actionDefine(calc.sign);

Uildel ul = (Uildel) Class.forName(className).newInstance();
ul.action(calc.val1, calc.val2);
ul.display();
System.out.println("Finish");
}

}
class Controller{
public static String actionDefine(char sign){
String className = null;
switch(sign){
case '+':
className = "Nemeh";
break;
default: System.out.println("Uuchlaarai iim uildel Version 2.0 deer nemegdene.");
}
return className;
}
}
abstract class Uildel{
private char sign;
protected double resultVal = 0;
public char getSign(){
return this.sign;
}
abstract public void action(double val1, double val2);
public void display(){
System.out.println(this.resultVal);
}
}
class Nemeh extends Uildel{
private char sign = '+';
private String className = "Nemeh";
public void action(double val1, double val2){
this.resultVal = val1 + val2;
}
}