-
June 9th, 2012, 12:18 PM
#1
Calc do while loop and phrasing gone wrong.. :(
hello, just tinkered with some good ol Eclipse after a 1 year programming rest..
and i cant seem to find out what the F is wrong here...
"cannot be resolved" errors are everywhere..
HELP and advise would be very much appreciated..
HERE IS MY CODE:
MAIN CLASS
package methodsWithParam2;
import java.util.Scanner;
public class mainClass {
public static void main(String args[]){
do{
Scanner jc = new Scanner(System.in);
int x,y,ch;
subClassSum subClassSumObject = new subClassSum();
subClassDiff subClassDiffObject = new subClassDiff();
subClassMult subClassMultObject = new subClassMult();
subClassDiv subClassDivObject = new subClassDiv();
subClassMod subClassModObject = new subClassMod();
System.out.println("Enter 1st number: ");
x = jc.nextInt();
System.out.println("Enter 2nd number: ");
y = jc.nextInt();
int total = (x+y);
int difference = (x-y);
int product = (x*y);
int quotient = (x/y);
int modulo = (x&y);
System.out.println("Please choose operation");
System.out.println("1. Addition \n2. Subtraction\n3. Multiplication\n4. Division");
ch = jc.nextInt();
switch(ch){
case 1:
subClassSumObject.sum(total);
break;
case 2:
subClassDiffObject.diff(difference);
break;
case 3:
subClassMultObject.prod(product);
break;
case 4:
subClassDivObject.quo(quotient);
subClassModObject.myMod(modulo);
break;
default:
System.out.println("Invalid operation");
break;
}
System.out.println("More? [1=Y / 2=N]");
int z = jc.nextInt();
}
while(z == '1');
System.out.println("Thank you!");
}
}
SUM DIFF MULT DIV AND MODULUS METHODS
package methodsWithParam2;
import java.util.Scanner;
public class subClassSum {
public void sum(int total){
System.out.println("Dude sum of the two is: " + total);
}
}
package methodsWithParam2;
import java.util.Scanner;
public class subClassDiff {
public void diff(int difference){
System.out.println("Dude difference of the two is: " + difference);
}
}
package methodsWithParam2;
import java.util.Scanner;
public class subClassMult {
public void prod(int product){
System.out.println("Dude product of the two is: " + product);
}
}
package methodsWithParam2;
import java.util.Scanner;
public class subClassDiv {
public void quo(int quotient){
System.out.println("Dude quotient of the two is: " + quotient);
}
}
package methodsWithParam2;
import java.util.Scanner;
public class subClassMod {
public void myMod(int modulo){
System.out.println("remainder is " + modulo);
}
}
THANK YOU IN ADVANCE!
JC -MANILA,PHILIPPINES
-
June 9th, 2012, 01:57 PM
#2
Re: Calc do while loop and phrasing gone wrong.. :(
you should really sepparate your classes with the thingies, you got me really confused for a second.
BTW are you talking about the "SUM DIFF MULT DIV AND MODULUS METHODS" line (having the "cannot be resolved to a type" problems)?
I believe you wanted to make it a comment? :-?
oh, also you can't use a variable that you defined in a loop in another loop - int z;
Last edited by cens; June 9th, 2012 at 02:02 PM.
-
June 10th, 2012, 07:59 AM
#3
Re: Calc do while loop and phrasing gone wrong.. :(
oh sorry bout the confusion sire..
the
SUM DIFF MULT DIV AND MODULUS METHODS
line in actually not included on the code itself..
i just posted the code of every separated methods.. those pieces of codes that follow are the ones being called..
i should have arranged them more clearly.. sorry bout that.. but anyways.. the latter part of your reply made sense bout int z being defined inside the loop..
thanks a ton sire!
-Jc,Philippines
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|