Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND SHIT)

How do I made forum
User avatar
D-vid
Posts: 11287
Joined: Wed Nov 03, 2010 5:10 pm
Location: Land of Beer and Sausage

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by D-vid »

O Notation is going to be the death of me and my IT degree.
Can anyone offer help?
Image

Image

User avatar
Madican
No face
Posts: 13531
Joined: Mon Feb 21, 2011 1:18 am

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by Madican »

daisies you Java. Okay, I have a Java program I'm writing for homework and there's just one error left for me to fix, except it's not a technical error so Netbeans thinks there's nothing wrong.

The goal is to input imaginary sales for a salesperson, calculate their commission (if any), then output their commission + fixed salary for a total. The sales also need to be shown on a table in $5,000 increments above the actual, capped at 150% of the actual, that shows the potential totals of those increments. This is where the problem is. The table shows up and so do the tiers of sales, but the totals remain the same no matter what. I'll try showing the code I have to see if anyone can figure out what I'm doing wrong.

Code: Select all

import java.util.*;
        
public class Calculator {
public static void main(String[] args) {
    
    Scanner input = new Scanner(System.in);
        //Scanner class imported to utilize keyboard input.
    
    double fixedSalary = 100_000;
    double annualSales;
    double commissionValue;
    double commissionRate = .05;
    double salesTarget = 120_000;
    double salesBegin = 96_000;
    double totalCompensation;
    double maximumAnnualSales;
    double maximumCompensation;
        //Variable names describe what they represent clearly.
        
    System.out.print("Enter salesperson's total annual sales: $");
    annualSales = input.nextDouble();
        //User inputs the amount of sales the salesperson has made.
    
    while (annualSales < 0 || annualSales > 99999999)
    {
        System.out.println("Invalid input.");
        System.out.println();
        System.out.print("Enter salesperson's total annual sales: $");
        annualSales = input.nextDouble();
        //If the input is invalid the user is notified and prompted
        //to enter valid input.
    }
    
    if (annualSales >= salesBegin && annualSales < salesTarget) {
        commissionValue = (annualSales * commissionRate);
        //If the sales are over 80% of the sales target but don't meet it
        //then the sales incentive executes.
    }
    else if (annualSales >= salesTarget) {
        commissionValue = ((annualSales * commissionRate) * 1.25);
        //If the sales meet or exceed the sales target it adds on
        //the acceleration factor to the output.
    }
    else commissionValue = 0;
        //If no conditions are met then there is no commission.
    
    totalCompensation = fixedSalary + commissionValue;
        //Final total
    
    System.out.println("Salesperson's total annual compensation is: "
        + "$"
        + totalCompensation  
    );
        //The program outputs the total annual compensation of the salesperson.
      
    System.out.println();
        //Blank line to separate from the total.
    System.out.println("Total Possible Sales \t Total Possible Annual Compensation" );
    
    maximumAnnualSales = annualSales * 1.5;
        //Maximum potential sales are 150% of actual.
      
    do {
        System.out.println("$" + annualSales
        + "\t\t" + "$" + totalCompensation);
        
        annualSales = annualSales + 5000;
        }
    while (annualSales <= maximumAnnualSales);
    //Loop takes annual sales and projects to 1.5 times the amount. Intention
    //is for annual compensation to do the same but the table shows identical
    //values and I can't figure out why since there are no explicit errors.
}       
    }
Stuff goes here later.

User avatar
D-vid
Posts: 11287
Joined: Wed Nov 03, 2010 5:10 pm
Location: Land of Beer and Sausage

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by D-vid »

I've never seen a while loop where the while is at the end. Have you tried using a repeat-until loop instead?
Unrelated, but you should idiot proof your input prompt. I think your program would throw a type mismatch exception if the user input something that's not a double.

Wait, I think I got it. Your compensation value simply never updates in the loop, so it's always the same value. Yeah I think that's it. You update your annual sales but your program doesn't go through the steps to calculate the comission anymore at that point.
Image

Image

User avatar
Madican
No face
Posts: 13531
Joined: Mon Feb 21, 2011 1:18 am

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by Madican »

I don't think that's it. I tried copy-pasting the sections where it does the calculations and while there are no errors it still outputs the same total.

Also I'm not sure how to idiot-proof the prompt.

EDIT: Wait I'm stupid. I wasn't supposed to copy-paste the calculations, I was supposed to copy-paste the conditionals that tell the program which calculation to use. Everything works perfectly now.
Stuff goes here later.

User avatar
D-vid
Posts: 11287
Joined: Wed Nov 03, 2010 5:10 pm
Location: Land of Beer and Sausage

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by D-vid »

Idiot proofing would be using a try - catch here.

try {
//what's supposed to be done } catch ( //exceptionname with some variable name, in this case it would be typeMismatchException I think but you can just use the generic Exception e) { //what to do if that exception happens, for example setting annualSales to -1 so it goes into that condition that lets you reinput}

Code: Select all

try {
   annualSales = input.nextDouble(); }
         catch (Exception e) {annualSales = -1; }
Image

Image

User avatar
Madican
No face
Posts: 13531
Joined: Mon Feb 21, 2011 1:18 am

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND S

Post by Madican »

That's a handy bit of code, thanks.
Stuff goes here later.

sadieblair
Posts: 1
Joined: Thu Sep 30, 2021 1:54 pm

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND SHIT)

Post by sadieblair »

Board post can become your chance to win the other students’ respect, become noticed by the professors, and practice wrote communication. In order to achieve all this, you need to do your best and focus while preparing your discussion post. However, you may ask for some help and say please, write my discussion board post

vivanort
Posts: 1
Joined: Fri Oct 22, 2021 10:56 am

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND SHIT)

Post by vivanort »

Even if you write essays every day and have a memo essay example in front of you, you may fail to provide a top-quality memo because it is a more formal piece that might create some difficulties for those who have never been involved in such an activity. As our writers to write me a memo and improve your grades!

Selvia58
Posts: 12
Joined: Sat Sep 18, 2021 5:20 pm

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND SHIT)

Post by Selvia58 »

Studies are the core base of society. We should make our children educated by giving them good education and awareness of society. These days it's very important for girls especially to protect themselves. I am looking for self defense classes near me so that I can my children aware and strong to live independently.

JuanCDean
Posts: 49
Joined: Sat Jul 17, 2021 7:32 am

Re: Study Buddies (AKA NOW LET US ALL NOT FAIL CLASSES AND SHIT)

Post by JuanCDean »

This pill can dissolve fat even in the worst circumstances thanks to its ingenious recipe for addressing low brown adipose tissue. This webpage has essay writing services cheap that any student can use if they want to get good scores so please go on thepoplarschool.com for best results This service will always satisfy the expectations of your lecturer at the lowest feasible rates, whether you are in New York, Chicago, or London. Exposure has been used by hundreds of women and men ranging in age from 18 to 70 years old, with excellent results.

Post Reply