I have to do this program where I have to display the calculation of the profit for each individual stock, but I also have to display the profit for the total amount of stocks. My code only has it so it displays the calculation for all of the stocks:
import java.util.Scanner;
public class KNW_MultipleStockSales
{
//This method will perform the calculations
public static double calculator(double numberShare, double purchasePrice,
double purchaseCommission, double salePrice,
double salesCommission)
{
double profit = (((numberShare * salePrice)-salesCommission) -
((numberShare * purchasePrice) + purchaseCommission));
return profit;
}
//This is where we ask the questions
public static void main(String[] args)
{
//Declare variables
Scanner scanner = new Scanner(System.in);
int stock;
double numberShare;
double purchasePrice;
double purchaseCommission;
double salePrice;
double saleCommission;
double profit;
double total = 0;
//Ask the questions
System.out.println("Enter the stocks you have: ");
stock = scanner.nextInt();
//For loop for the number stock they are in
for(int numberStocks=1; numberStocks<=stock; numberStocks++)
{
System.out.println("Enter the number of shares for stock " + numberStocks + ": ");
numberShare = scanner.nextDouble();
System.out.println("Enter the purchase price" + numberStocks + ": ");
purchasePrice = scanner.nextDouble();
System.out.println("Enter the purchase commissioned:" + numberStocks + ": ");
purchaseCommission = scanner.nextDouble();
System.out.println("Enter the sale price:" + numberStocks + ": ");
salePrice = scanner.nextDouble();
System.out.println("Enter the sales commissioned:" + numberStocks + ": ");
saleCommission = scanner.nextDouble();
profit = calculator(numberShare, purchasePrice, purchaseCommission,
salePrice, saleCommission);
total = total + profit;
}
//Return if the user made profit or loss
if(total<0)
{
System.out.printf("You made a loss of:$%.2f", total);
}
else if(total>0)
{
System.out.printf("You made a profit of:$%.2f", total);
}
else
{
System.out.println("You made no profit or loss.");
}
}
}
How can I get it so each individual stock profit gets shown, with the profit of all the stocks together?
Try maintaining a separate Map for profit/loss. You may want to accept Stock Name as an input which will help manage individual stocks effectively.
// Map of stock name and profit/loss
Map<String,Double> profitMap = new HashMap<String,Double>();
After calculating profit/loss, add entry to map
profitMap.put("stockName", profit);
total = total + profit;
At the end of your program, iterate and display profit/loss for each Stock from Map.
for (Entry<String, Integer> entry : profitMap.entrySet()) {
System.out.println("Stock Name : " + entry.getKey() + " Profit/loss" + entry.getValue());
}
Related
I haven't been able to make this code executable for class and can't find the reason why there are no errors prompting however when i execute i get this:
Exception in thread "main" java.lang.UnsupportedOperationException: Not
supported yet.
at set.fixedSalary(set.java:14)
at Main.main(Main.java:23)
C:\Users\the_h\AppData\Local\NetBeans\Cache\8.2\executor-
snippets\run.xml:53: Java returned: 1
I honestly have no idea how to fix this problem any help is appreciated I have the source code below.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private double fixedSalary;
private double commission;
private double salesTarget;
private double Acc_Rate;
private ArrayList<Double> annualSales;
private ArrayList name;
public static void main(String[] args){
// salesperson will earn a fixed salary of $32,600
set.fixedSalary(32600);
// The current sales target for every salesperson is $120,000.00
set.SalesTarget(120000.00);
//The acceleration factor is 2.1
set.Acc_Rate(2.1);
}
public ArrayList<Double> getAnnualSales(){
return annualSales;
}
public Main() {
this.name = new ArrayList();
this.annualSales = new ArrayList<>();
}
private float calculateCommission(double personSale) {
throw new UnsupportedOperationException("Not supported yet."); //To
change body of generated methods, choose Tools | Templates.
}
function read user input
class readData{
public void readData(){
// Creates a scanner object for sales entry.
Scanner input = new Scanner(System.in);
// prompts user for name of sales person
System.out.println("Please enter First Sales Person name: ");
name = addinput.nextLine();
// prompts user for name of sales person
System.out.println("Please enter 2nd Sales Person name: ");
name = addinput.nextLine();
//Prompts user for sales
System.out.println("Please enter annual sales First Person: ");
annualSales = addinput.nextDouble();
//Prompts user for sales
System.out.println("Please enter annual sales Second Person: ");
annualSales = addinput.nextDouble();
}
}
class calculateCommission {
double commission = 0.00;
double Acc_Rate;
calculateCommission() {
}
public double calculateCommission(double annualSales, double fixedSalary,
double salesTarget) {
this.Acc_Rate = 0.045 * annualSales;
double earnings = fixedSalary;
// The current commission is 4.5 of total sales
if(annualSales < 0.8 * salesTarget) {
earnings = fixedSalary + commission;
} else if (annualSales <= salesTarget){
//The current acc rate is 2.1 of total sales
commission = 0.045 * annualSales;
earnings = fixedSalary + commission;
} else if (annualSales > salesTarget){
earnings = fixedSalary + Acc_Rate;
}
return earnings;
}
} // function get commision
public double getCommission() {
return commission;
}
// function get total annual compensation
public double getTotalCommissionCalc(){
return fixedSalary + getCommission();
}
// funtion set value for fixedSalary
public void setfixedSalary(double fixedSalary){
this.fixedSalary = fixedSalary;
}
// funtion set value for salesTarget
public void setSalesTarget(double salesTarget){
this.salesTarget = salesTarget;
}
// funtion set value for incentive rate
public void setAcc_Rate(double Acc_Rate) {
this.Acc_Rate = Acc_Rate;
}
// Display a table of potential total annual compensation
public void displayResult(){
double annualSalesCalc;
double personSale;
for (int i = 0; i < name.size(); i++){
String personName = (String) name.get(i);
personSale = annualSales.get(i);
System.out.println("Total Compensation of Sales Person " +
personName + " is " + Math.round(calculateCommission(personSale)));
//Print column names
System.out.print("SalePerson\tTotal Sales\tTotal Compensation");
annualSalesCalc = personSale * 1.50;
while(personSale <= annualSalesCalc){
calculateCommission(personSale);
System.out.println((personName) + "\t\t" +
Math.round((personSale)) + "\t\t" +
Math.round(calculateCommission(personSale)));
personSale = personSale + 5000;
}
System.out.println(); // print blank line
}
if (annualSales.get(0) > annualSales.get(1)) {
System.out.println("Salesperson " + name.get(1)
+ "'s additional amount of sales that he must "
+ "achieve to match or exceed the higher of the salesperson
"
+ Math.round(annualSales.get(0)) + " is");
System.out.print("$" + Math.round((annualSales.get(0) -
annualSales.get(1))));
} else if(annualSales.get(1) > annualSales.get(0)){
System.out.println("Salesperson " + name.get(0)
+ "'s additional amount of sales that he must "
+ "achieve to match or exceed the higher of the salesperson
"
+ Math.round(annualSales.get(1)) + " is");
System.out.print("$" + Math.round((annualSales.get(1) -
annualSales.get(0))));
} else{
System.out.print("Both have same compensation");
}
}
}
It might be because your set.fixedSalary needs to be an integer because you dont set it as a double. you set it to 36000 when it needs to be 36000.0
/**I am trying to ask for user input for the number of the books they want to order, then using for find the cost of each book, total them up and give them their receipt at the end for their order. I understand how to give them the output just having trouble with my loop.*/
import java.util.Scanner;
public class BookOrder {
public static void main(String[] orgs){
Scanner in = new Scanner(System.in);
final double TAX = .065;
final double SHIPPING = 2.95;
int counter = 0;
double bookSubtotal, subtotal, taxPaid;
System.out.print("Please enter the number of books you're ordering: ");
double numberOfBooks = in.nextDouble();
for (counter = 0; counter < numberOfBooks; counter++){
System.out.println("Please enter the cost of your book: ");
double priceOfBooks = in.nextDouble();
bookSubtotal = priceOfBooks + bookSubtotal;
counter ++;
}
double subtotal = numberOfBooks * priceOfBooks;
double taxpaid = subtotal * (TAX);
double shippingCharge = SHIPPING * numberOfBooks;
double sumOfOrder = bookSubtotal + priceOfOrder + shippingCharge + TAX;
System.out.println("Number of books purchased:" + numberOfBooks);
System.out.println("Book subtotal: $" + subtotal);
System.out.println("Tax: $" + taxPaid);
System.out.println("Shipping: $" + shippingCharge);
System.out.println("-------------------------------");
System.out.println("The price of the order is $" + sumOfOrder + ".");
}
}
You seem to increment counter twice:
for (counter = 0; counter < numberOfBooks; counter++){
System.out.println("Please enter the cost of your book: ");
double priceOfBooks = in.nextDouble();
bookSubtotal = priceOfBooks + bookSubtotal;
counter ++;//this line
}
What happens in this line is that you increment counter, but the loop does that for you, because of:
for(counter = 0;counter<numberOfBooks;counter++)
the counter++ in that line increments counter for you, so just remove the
counter++;
line in the for loop (the one I wrote this line next to)
Also, you should set a value to bookSubtotal:
int bookSubtotal = 0;
in the beginning.
Additionally, you might want to make numberOfBooks an integer:
int numberOfBooks = in.nextInt();
And you shouldn't re declare subtotal twice, just remove the word double in the line:
double subtotal = (double)numberOfBooks * priceOfBooks;
Nor do you need the create taxpaid before the loop, because you have taxPaid after it. Naming is case sensitive, meaning capital letters Are ImpOrtaNt...
public class BookOrder {
public static void main(String[] orgs){
Scanner in = new Scanner(System.in);
final double TAX = .065;
final double SHIPPING = 2.95;
int counter = 0;
double bookSubtotal = 0;
System.out.print("Please enter the number of books you're ordering: ");
int numberOfBooks = in.nextInt();
for (counter = 0; counter < numberOfBooks; counter++){
System.out.println("Please enter the cost of your book: ");
double priceOfBooks = in.nextDouble();
bookSubtotal += priceOfBooks;
}
double shippingCharge = SHIPPING * numberOfBooks;
double tax = TAX * bookSubtotal;
double sumOfOrder = bookSubtotal + shippingCharge + tax;
System.out.println("Number of books purchased:" + numberOfBooks);
System.out.println("Book subtotal: $" + bookSubtotal);
System.out.println("Tax: $" + tax);
System.out.println("Shipping: $" + shippingCharge);
System.out.println("-------------------------------");
System.out.println("The price of the order is $" + sumOfOrder + ".");
}
}
I am creating a program that basically asks a user what they wish to purchase and gives them their total.
I am supposed to use 2 separate methods outside of Main to complete this task:
One method to get the user input as to which service they want performed, this method will also tell the user the total cost of the services (BEFORE TAX AND LABOR)
Another method to calculate labor costs and tax costs
The first method should return total cost to the main method, and the second method should get that total from the main method and calculate the Final Cost after labor and tax are added in.
(if the car is an import, 5% of the total should be added on)
Here is what I have so far:
import java.util.Scanner;
public class Assign3 {
public static double carMaintenance(String userCar) {
Scanner input = new Scanner(System.in);
String service_ordered="";
String more="yes";
double amount;
double total=0;
//declare and intialize parallel arrays, Services and Prices and display them to the user
String[] services = {"Oil Change" , "Tire Rotation", "Air Filter", "Fluid Check"}; //intialize list of services
double[]price = {39.99, 49.99, 19.99, 10.99}; //initialize corresponding price for services
for(int i= 0; i < services.length; i++) {
System.out.print( services[i]+ "...." );
System.out.print( price[i] + "\t");
}
do // *****2. THIS IS WHAT IS BEING EXECUTED FROM THE METHOD CALL IN MAIN *****
{
System.out.print("What service do you want done?: ");
String choice = input.nextLine();
if (choice.equalsIgnoreCase("oil change")) {
System.out.println("You chose an oil change");
amount = 39.99;
total = total + amount;
service_ordered+="Oil Change ";
System.out.print("Do you want to do another service? ");
more = input.nextLine();
} else if (choice.equalsIgnoreCase("tire rotation")) {
System.out.println("You chose a tire rotation");
amount = 49.99;
total = total + amount;
service_ordered+="Tire Rotation ";
System.out.print("Do you want to do another service? ");
more = input.nextLine();
} else if (choice.equalsIgnoreCase("air filter")) {
System.out.println("You chose an air filter");
amount = 19.99;
total = total + amount;
service_ordered+="Air Filter ";
System.out.print("Do you want to do another service? ");
more = input.nextLine();
} else if (choice.equalsIgnoreCase("fluid check")) {
System.out.println("You chose a flud check");
amount = 10.99;
total = total + amount;
service_ordered+="Fluid Check ";
System.out.print("Do you want to do another service? ");
more = input.nextLine();
}
} while (more.equalsIgnoreCase("yes"));
System.out.println("You ordered: " + service_ordered);
System.out.println("Your total due is " + total);
return total;
}
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
System.out.println("What kind of car do you have?: "); //****1. CODE STARTS HERE *****
String userCar = input.nextLine();
double total = carMaintenance(userCar); //*****2. CODE CALLS THIS METHOD AND EXECUTES IT *****
calcFinalPrice(total);
}
public static void calcFinalPrice(double total) {
double salesTax=.08;
double laborFee=.3;
double importFee=.05;
Scanner input = new Scanner(System.in);
System.out.println("Is your vehicle an import?: ");
String isImport = input.nextLine();
if(isImport.equals("yes")) {
total=total*laborFee+total; // this is the labor fee
double importTotal = total*importFee+total;
double totalAfterTax = importTotal*salesTax+importTotal; //this is the import total aftertax
System.out.println("It will cost " + totalAfterTax + " to fix your vehicle.");
}
if(isImport.equals("no")) {
total=total*laborFee+total; // this is the labor fee
double totalAfterTax = total*salesTax+total; //this is the total aftertax
System.out.println("It will cost " + totalAfterTax + " to fix your vehicle ");
}
}
}
what the program wants me to code:
Code an executable program that will produce
an invoice for a customer ordering a number
of products at a store. A sample run of the
program is shown to the right.
Your program
must ask for the number of products (up to a
maximum of 12 products may be ordered) and
then successively ask for the product name and
its cost. The invoice produced includes:
the title of the store (as shown),
product names and their cost,
calculated cost of all products,
calculated 5% sales tax,
overall total cost
a thank you.
The products and their cost must be kept in
parallel arrays. Two methods must be coded.
One method will display the title. The second
method will accept the calculated cost of all
products and return the calculated sales tax.
The method that computes the sales tax must
use a named constant for the 5% tax rate.
picture of example run of what it should look like: http://imgur.com/F3XDjau
Currently my program is this so far, but im not sure if it is correct or if i need to make the variables into an array.
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
int product;
String products;
double cost;
System.out.println("How many products? ");
product=input.nextInt();
for(int i = 0; i < product; i++){
System.out.println("Product Name: ");
products=input.next();
System.out.println("Cost: ");
cost=input.nextDouble();
}
}
}
this is how you can fill your array:
double[] costArray = new double[product];
for(int i = 0; i < product; i++){
costArray[i] = input.nextDouble();
}
You need to use an array for variables products and cost like this:
static final float TAXES = 0.05f;
public static void main(String[] args) {
double sum = 0.0;
double tax;
Scanner input = new Scanner(System.in);
int product;
String products[];
double cost[];
System.out.println("How many products? ");
product = input.nextInt();
products = new String[product];
cost = new double[product];
for (int i = 0; i < product; i++) {
System.out.println("Product Name: ");
products[i] = input.next();
System.out.println("Cost: ");
cost[i] = Double.parseDouble(input.next().trim().replace(',', '.'));
}
indentedText();
for (int i = 0; i < product; i++) {
System.out.printf(products[i] + '\t' + "%.2f %n", cost[i]);
sum = sum + cost[i];
}
tax = calculateTaxes(sum);
System.out.printf("Sub total:" + '\t' + "%.2f %n", sum);
System.out.printf("Sales tax:" + '\t' + "%.2f %n", tax);
System.out.printf("Total to be paid:" + '\t' + "%.2f %n %n", (sum + tax));
System.out.print('\t' + "Thank you!");
}
private static void indentedText() {
System.out.print('\t' + "The Company Store" + '\n' + '\n');
}
private static double calculateTaxes(double sum) {
return sum * TAXES;
}
I'm sorry if this has been asked before somewhere, but I really haven't seen anything that helps with the exact question that I have. This is for school work, but I've beat myself up for 2 days over trying to figure out what I'm doing wrong, so if someone can help I would more than appreciate it.
I have a program that is basically supposed to enter the name of two sales people, show a table of their potential earnings, and finally compare the differences in their sales. I'm doing this in NetBeans IDE, and I've got all sorts of things in here trying to figure it out.
Everything works fine until I try to pull anything out of my ArrayLists. I was thinking it should be possible to store something in there, then pull it back out to do the math I need to do but I must be doing something wrong. Here's the specific Class code I'm having problems with:
class EarningDifference {
SalesPerson persons = new SalesPerson(); //Access to SalesPerson class
AnnualSales aSaleC = new AnnualSales(); //Access to AnnualSales class
ArrayList<SalesPerson> list = new ArrayList<>(); //Access to SalesPerson ArrayList
ArrayList<AnnualSales> aSales = new ArrayList<>(); //Access to AnnualSales ArrayList
AnnualSales person1EarningStr; //Person one earnings from AnnualSales ArrayList
AnnualSales person2EarningStr; //Person two earnings from AnnualSales ArrayList
Double person1Earning; //Person one earnings as double
Double person2Earning; //Person two earnings as double
String person1; //String for person one full name
String person2; //String for person two full name
Double difference; //Variable to store the difference between Person1 and Person2 sales
double totalSales; //variable for Total sales
public void people() {
person1 = list.get(0).getFirstName() + " " + list.get(0).getLastName();
person2 = list.get(1).getFirstName() + " " + list.get(1).getLastName();
System.out.println("Comparing " + person1 + " with " + person2 + ".");
}
void settotalSales(Double totalSales) {
this.totalSales = totalSales;
AnnualSales person1EarningStr = aSales.get(0);
AnnualSales person2EarningStr = aSales.get(1);
double person1Earning = person1EarningStr.doubleValue();
double person2Earning = person2EarningStr.doubleValue();
if (aSales.size() < 2) {
System.out.println("Need another person to compare");
} else if (person1Earning > person2Earning) {
difference = person1Earning - person2Earning;
System.out.println(person1 + " has earned " + difference + " more in sales than " + person2 + ".");
} else {
difference = person2Earning - person1Earning;
System.out.println(person2 + " has earned " + difference + " more in sales than " + person1 + ".");
}
}
}
Here is the class where items are added to the AnnualSales ArrayList:
public class SalaryTotal {
double fixedSalary; //Variable for the fixed salary amount
double commission; //Variable for the comission
double minimumSales; //Variable to define the minimum amount of annual sales sales persn must make to receive compensation
double maximumSales; //Variable to define the number after which commission increases
double advanceRate; //Variable used to define the rate at which compensation increases after minimum sales are met
double compensation; //Variable for the amount of compensation based on sales
double totalSalary; //Variable for the total salary
double totalSales;
Double compensationD;
SalesPerson persons = new SalesPerson();
ArrayList<SalesPerson> list = new ArrayList<>();
ArrayList<Double> aSales = new ArrayList<>();
public void getCompensation(double totalSales) {
commission = .21; //The constant commission rate
minimumSales = 120000; //The constant minimum sales needed to receive compensation
maximumSales = 150000; //The constant maximum amount above which commission increases by the advanceRate
advanceRate = 1.67; //The constant at which compensation increasea after minimum sales
this.totalSales = totalSales;
if (totalSales < minimumSales) {
compensation = 0; //sets compensation to 0 if minimum sales are not met
} else if (totalSales <= 150000){
compensation = totalSales * commission + fixedSalary; //calculates total of compensation if total sales meet minimum sales
} else if (totalSales > maximumSales) {
compensation = totalSales * commission * advanceRate + fixedSalary; //calculates total compensation if total sales exceed maximum sales
}
Double compensationD = new Double(compensation);
aSales.add(compensationD);
System.out.println("Current total compensation:" + compensation);
for (int i = 0; i < aSales.size(); i++) {
System.out.println(aSales.get(i));
System.out.println("Show " + persons.makePerson1() + ".");
}
}
}
}
I'm sure this is a complete mess of bad coding, but any help would be appreciated, just ignore the random bits of odd coding I put in to try to narrow down what my issue is. Thank you so much.
The rest of the program look like this, I've also removed the bits that were just in for problem testing from previous portions
Main:
import java.util.Scanner; //Needed for scanner input
import java.text.DecimalFormat; //Needed for correct output of decimals
import java.util.ArrayList;
public class AnnualCompensation {
private static String Y;
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("$###,###.00"); //This will correctly format the money amounts
Double totalSales;
int startY;
ArrayList<SalesPerson> list = new ArrayList<>();
ArrayList<AnnualSales> aSales = new ArrayList<AnnualSales>();
Scanner start = new Scanner(System.in); //Creates scanner input
System.out.println("Are you ready to compare sales? Press 1 if yes, 2 if no."); //Prints out entry command
startY = start.nextInt();
switch (startY){
case 1:
InputClass inputs = new InputClass();
inputs.getInputs();
break;
case 2:
System.out.println("Thank you anyway!");
System.exit(0);
break;
default:
System.out.println("You have selected neither Y or N, please try again.");
System.exit(0);
}
SalaryTotal calculator = new SalaryTotal(); //Calls class SalaryTotal
PossibleCompensation table = new PossibleCompensation(); //Calls class PossibleCompensation
}
}
Possible Compensation:
public class PossibleCompensation {
SalesPerson persons = new SalesPerson();
ArrayList<SalesPerson> list = new ArrayList<>();
ArrayList<AnnualSales> aSales = new ArrayList<AnnualSales>();
DecimalFormat df = new DecimalFormat("$###,###.00"); //This will correctly format the money amounts
double commission; //Variable for the comission
double minimumSales; //Variable to define the minimum amount of annual sales sales persn must make to receive compensation
double maximumSales; //Variable to define the number after which commission increases
double advanceRate; //Variable used to define the rate at which compensation increases after minimum sales are met
double compensation; //Variable for the amount of compensation based on sales
double totalSales; //Variable for sales person annual sale
public void settotalSales(double totalSales) {
for (int i = 0; i < list.size(); i++)
this.totalSales = totalSales; //Sets the input from AnnualCompensation to totalSales in this class
commission = .21; //The constant commission rate
minimumSales = 120000; //The constant minimum sales needed to receive compensation
maximumSales = 150000; //The constant maximum amount above which commission increases by the advanceRate
advanceRate = 1.67; //The constant at which compensation increasea after minimum sales
String heading1 = "Total Sales"; //variable to print a header for the table
String heading2 = "Total Compensation"; //variable to print a header for the table
System.out.print("\nBelow is a table based on possible commissions if sales increase:\n"); //Prints instructions
System.out.printf("\n%20s %20s", heading1, heading2); //prints header and formats spacing
for (double i=totalSales; i <= (totalSales * 1.5); i+= 5000) { //FOR loop for calculating and constructing table
if (i < minimumSales) {
compensation = 0; //sets compensation to 0 if minimum sales are not met
} else if (i <= 150000){
compensation = i * commission; //calculates total of compensation if total sales meet minimum sales
} else if (i > maximumSales) {
compensation = i * commission * advanceRate; //calculates total compensation if total sales exceed maximum sales
}
System.out.printf("\n%20s %15s", df.format(i), df.format(compensation) + "\n"); //Prints out the table
}
}
}
class SalesPerson {
String firstName;
String lastName;
String totalSalesStr;
ArrayList<SalesPerson> list = new List<>();
SalesPerson class:
public SalesPerson() {
this.firstName = firstName;
this.lastName = lastName;
this.totalSalesStr = totalSalesStr;
}
SalesPerson(String firstName, String lastName, String totalSalesStr) {
this.firstName = firstName;
this.lastName = lastName;
this.totalSalesStr = totalSalesStr;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public String getTotalSalesStr() {
return this.totalSalesStr;
}
public Double getTotalSales() {
Double totalSales = Double.parseDouble(totalSalesStr);
return totalSales;
}
public String makePerson1() {
String person1 = list.get(0).getFirstName() + " " + list.get(0).getLastName();
return person1;
}
public String makePerson2() {
String person2 = list.get(1).getFirstName() + " " + list.get(1).getLastName();
return person2;
}
#Override
public String toString() {
return ("Sales person " + this.getFirstName() + " " + this.getLastName() + " has annual sales of " + this.getTotalSalesStr() + ".");
}
}
class AnnualSales {
Double compensationD;
AnnualSales person1EarningStr;
AnnualSales person2EarningStr;
ArrayList<AnnualSales> aSales = new ArrayList<AnnualSales>();
public AnnualSales() {
this.compensationD = compensationD;
}
public AnnualSales(Double compensationD) {
this.compensationD = compensationD;
}
public Double getCompensationD() {
return this.compensationD;
}
public AnnualSales getperson1EarningStr() {
person1EarningStr = aSales.get(0);
return person1EarningStr;
}
public AnnualSales getperson2EarningStr() {
person2EarningStr = aSales.get(1);
return person2EarningStr;
}
#Override
public String toString() {
return ("please show us" + compensationD);
}
}
Input class:
class InputClass {
String firstName;
String lastName;
Double totalSales;
String totalSalesStr;
CopyOnWriteArrayList<SalesPerson> list = new CopyOnWriteArrayList<>();
public void getInputs() {
for(double i=0; i < 2; i++){
Scanner persFN = new Scanner(System.in); //Creates scanner input
System.out.println("Enter sales person's first name:"); //Prints out entry command
String firstName = persFN.next();
Scanner persLN = new Scanner(System.in); //Creates scanner input
System.out.println("Enter sales person's last name:"); //Prints out entry command
String lastName = persLN.next();
Scanner input = new Scanner(System.in); //Creates scanner input
System.out.println("Enter Total Sales:"); //Prints out entry command
totalSales = input.nextDouble();
String totalSalesStr = totalSales.toString();
list.add(new SalesPerson(firstName, lastName, totalSalesStr));
SalaryTotal calculator = new SalaryTotal(); //Calls class SalaryTotal
calculator.getCompensation(totalSales);
PossibleCompensation table = new PossibleCompensation(); //Calls class PossibleCompensation
table.settotalSales(totalSales);
EarningDifference earning = new EarningDifference();
earning.settotalSales(totalSales);
}
}
}
I think that should be everything related!
Make sure you have override equals() method in your Classes. As a good practice always make sure you have override both equals() and hashCode().
Why?
From Java doc.
Removes the first occurrence of the specified element from this list,
if it is present. If the list does not contain the element, it is
unchanged. More formally, removes the element with the lowest index i
such that (o==null ? get(i)==null : o.equals(get(i))) (if such an
element exists). Returns true if this list contained the specified
element (or equivalently, if this list changed as a result of the
call).
If your ArrayList element not a String(more generally if it is not a inbuilt Java class), You need to override equals() method.