class - Using 2 classes for a Comission Calculator in Java -
i doing assignment beginning java class. have write commission calculator , use 2 classes in it. stuck on how use variables 1 class in second class. methods have found far not working me. advice helpful. below code have far.
package calc; /** * * @author ethan */ import java.util.scanner; public class calc { public static void main(string[] args) { scanner calcu = new scanner(system.in); //creats scanner used input //sets of variables used double sal; //salary double com1; //comission percentage double com2; // find ammount of comisssion yearly sales double comp; //yearly sales double frac; //decimal comission form double total; // total of compensation of yearly salary + comission system.out.println("enter annual salary here: "); sal = calcu.nextdouble(); system.out.println("enter total sales here: "); comp = calcu.nextdouble(); rate(); frac = com1/100; //converts sales comission decimal com2 = frac * comp; // find total comission based on total = sal + com2; //find total compensation system.out.print("your total compensation " + total); } private static void rate(){ // rate of commission determined below. if (comp < 10000) com1 = 20; //20% commission rate else if (comp < 30000) com1 = 22; // 22% commission rate else if (comp < 50000) com1 = 23; // 23% commission rate else if (comp < 100000) com1 = 24; // 24% commission rate else com1 = 25; // 25% commission rate } }
the problem have can't pull rates can used in calculations.
a few major issues on code. code encapsulated in calc class, no constructor ever called. (eg. new calc()). rate() method in calc, called calc.rate(). check out few more examples of how construct java class, , understand encapsulation of variables.
Comments
Post a Comment