Hello Java Forums, I am currently starting a Java Course in school and was hoping to get a little help. I won't be one to post an entire assignment, I am simply looking to pass a double value from one class to another to separate the final outputs.
Here is my first class
package salesperson_part1; import java.io.IOException; // For BufferReader import java.io.InputStreamReader; // For BufferReader import java.io.BufferedReader; // For BufferReader public class Salesperson_Part1 { public static void main(String[] args) { int fixedSalary = 50000; // SalesPerson Fixed Salary System.out.println("Total Annual Compensation is an accumulation of your " + "fixed salary, $" + fixedSalary + ",\nplus a 15 percent commission " + "on all sales for the year."); double salesAmount; //Amount sold for the year System.out.print("\nWhat were your total sales amount for the year? "); try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = in.readLine().trim(); if (line == null || line.length() == 0) { System.out.println("Canceled."); return; } salesAmount = Double.parseDouble(line); } catch (NumberFormatException exception) { System.out.println("Error: Not a valid sales amount."); return; } catch (IOException exception) { System.out.println("Error: " + exception.getLocalizedMessage()); return; } } }
And here is the second:
package salesperson_part1; class output { double commission = (salesAmount * 0.15); System.out.print("\nYour total commission is $" + commission); double AnnualCompensation = commission + 50000; System.out.print("\nYour total Anual Compensation is $" + AnnualCompensation + "\n\n"); }
So how can I get "SalesAmount" accessible in my second class in order to perform these operations upon it?
Thank you so much, I am sure after I understand this first class passing method, it will facilitate it in the future for me