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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -