ווער וויל מיך אויסלערנען JAVA ?
פארעפענטליכט: דינסטאג פבואר 21, 2012 2:58 pm
איך פרוביר צומאכעו א קאלקולעטער
נאכען אסאך ליינען האב איך קודם דאס אהער געשטעלט
דאס איז די מעין מעטאד
און דאס ענהאלט די קלאס
נאכען אסאך ליינען האב איך קודם דאס אהער געשטעלט
דאס איז די מעין מעטאד
- קאוד:
import static java.lang.System.out;
public class ProfessionalCalculator {
public static void main(String[] args) {
MathCalculator first = new MathCalculator();
out.println("welcome to my calculator");
first.promptForFirstInput();
first.firstInput = first.input.nextDouble();
first.promptForSecondInput();
first.method = first.input.nextInt();
first.myWhile();
first.promptForThirthInput();
first.secondInput = first.input.nextDouble();
first.myResults();
}
}
און דאס ענהאלט די קלאס
- קאוד:
import java.util.Scanner;
public class MathCalculator {
Scanner input = new Scanner (System.in);
double firstInput ;
int method ;
double secondInput;
double results;
void promptForFirstInput() {
System.out.println("enter the first amount : ");
}
void promptForSecondInput() {
System.out.println("enter 1=+ 2=- 3=* 4=/ : ");
}
void promptForThirthInput() {
System.out.println("enter the second amount : ");
}
void myWhile()
{
while (method >4)
{
System.out.println("pleas enter a valid number");
promptForSecondInput();
method = input.nextInt();
}
}
void myResults() {
switch (method) {
case 1:
System.out.println(firstInput + secondInput);
break;
case 2:
System.out.println(firstInput - secondInput);
break;
case 3:
System.out.println(firstInput * secondInput);
break;
case 4 :
System.out.println(firstInput / secondInput);
break;
default:
System.out.println("i dont know what u entered");
break;
}
}
}