Trouble with manipulating user input and placing in a table.

  • Basic Chaos
  • Born
  • Born
  • Basic Chaos
  • Posts: 2

Post 3+ Months Ago

This was a homework problem from last week. I got a D on it because it was incomplete and tuned in a day late
The exact wording of the problem was the following:
 A salesperson will continue to earn a fixed salary of $30,000. The current sales target for every salesperson is $400,000.
 The sales incentive will only start when 80% of the sales target is met. The current commission is 8% of total sales.
 If a salesperson exceeds the sales target, the commission will increase based on an acceleration factor. The acceleration factor is 1.25
 The application should ask the user to enter annual sales, and it should display the total annual compensation.
 The application should also display a table of potential total annual compensation that the salesperson could have earned, in $5000 increments above the salesperson’s annual sales, until it reaches 50% above the salesperson’s annual sales.
Sample Table: Assuming a total annual sales of $100,000, the table would look like this:
Total Sales
Total Compensation
100,000 <<Program calculated value>>
105,000 <<Program calculated value>>
110,000 <<Program calculated value>>
115,000 <<Program calculated value>>
120,000 <<Program calculated value>>
125,000 <<Program calculated value>>
130,000 <<Program calculated value>>
135,000 <<Program calculated value>>
140,000 <<Program calculated value>>
145,000 <<Program calculated value>>
150,000 <<Program calculated value>>
The Java™ application should also meet these technical requirements:
The application should have at least one class, in addition to the application’s controlling class.
The source code must demonstrate the use of conditional and looping structures.

I have created tables before such as the one below, but this one requires me to enter each amount manually. I haven't the first clue about how to make a program that can retrieve user input, perform calculations and display those results in a table. Here is the table I created, but it will not work for this program.
Code: [ Select ]

   import java.awt.*; 
  import javax.swing.*; 
  class TableDemo { 
    public static void main(String args[]) 
    { 
   
      JFrame frame = new JFrame("Commission Sample Table"); 
      String columns[] = {"Total Sales","Total Compensation"}; 
      Object data[][] = { 
          {"$400,000","$62,000"}, 
          {"405,000","$67,000"}, 
          {"410,000","$67,925"} 
      }; 
      JTable table = new JTable(data,columns); 
      frame.setVisible(true); 
      frame.setBounds(0,0,600,600); 
      frame.add(table.getTableHeader(),BorderLayout.PAGE_START); 
      frame.add(table); 
    } 
  } 
  1.    import java.awt.*; 
  2.   import javax.swing.*; 
  3.   class TableDemo { 
  4.     public static void main(String args[]) 
  5.     { 
  6.    
  7.       JFrame frame = new JFrame("Commission Sample Table"); 
  8.       String columns[] = {"Total Sales","Total Compensation"}; 
  9.       Object data[][] = { 
  10.           {"$400,000","$62,000"}, 
  11.           {"405,000","$67,000"}, 
  12.           {"410,000","$67,925"} 
  13.       }; 
  14.       JTable table = new JTable(data,columns); 
  15.       frame.setVisible(true); 
  16.       frame.setBounds(0,0,600,600); 
  17.       frame.add(table.getTableHeader(),BorderLayout.PAGE_START); 
  18.       frame.add(table); 
  19.     } 
  20.   } 


The table can be an array, a list, or anything so long as it displays the required results.
I have already used a pencil and paper to write down what I think needs to be done in English. The following is what I came up with: Retrieve the user's input. Increase user input by 5000 until it reaches 50% above the original amount. Display each of the incremented amounts in column 1 of a table. Display how much compensation would have been received for each amount in column 2.

I have tried building a subclass to extend AnnualPayCalculator, I have tried using a "for loop", and I have also tried to just make the program simply print the output with system.out.println. My main problem is that I have only been learning about Java for a little more than three weeks and I understand almost none of what I read about it.

I have also recently tried the following:

Code: [ Select ]
int sum = 0;
for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
sum += i;
System.out.println(sum);

//and

do ( salesAmount >= 320000
System.out.print( salesAmount * 0.925 );

( salesAmount < 320000
System.out.print("Total Sales " +( salesAmount * 0.08 ));

while (salesAmount < salesAmount*1.5)
system.out.print( salesAmount+=5000 )

if (salesAmount < salesAmount*1.5
system.out.print("Total Compensation" + ( 0.8*salesAmount+30000 ));

System.out.println("firstcolumn\tSecondColumn\tThirdColumn");
}
}
  1. int sum = 0;
  2. for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
  3. sum += i;
  4. System.out.println(sum);
  5. //and
  6. do ( salesAmount >= 320000
  7. System.out.print( salesAmount * 0.925 );
  8. ( salesAmount < 320000
  9. System.out.print("Total Sales " +( salesAmount * 0.08 ));
  10. while (salesAmount < salesAmount*1.5)
  11. system.out.print( salesAmount+=5000 )
  12. if (salesAmount < salesAmount*1.5
  13. system.out.print("Total Compensation" + ( 0.8*salesAmount+30000 ));
  14. System.out.println("firstcolumn\tSecondColumn\tThirdColumn");
  15. }
  16. }

I cannot understand how to use the code to make the program do what I want. The first part of my code was the result of four days spent trying different combinations until I finally got one to compile. It was sincerely pure luck that it worked. I am trying everything I can think of for the last part of the code, but nothing has produced the results I am expecting. I really want to learn how to make it work. I just need some guidance about what I should be doing to get this to work.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Basic Chaos
  • Born
  • Born
  • Basic Chaos
  • Posts: 2

Post 3+ Months Ago

I forgot to add my original code!!!!!! here it is. Sorry for that.

Code: [ Select ]
import java.util.Scanner; //needed to obtain user input

public class AnnualPayCalculator
{
public static void main(String[ ] args)

{
double salesAmount ; //declare variables

// Create Scanner object to obtain user input.
Scanner keyboard = new Scanner(system(dot)in); ///I wrote (dot) here because it would not let me post because it was assuming this was a web address, which it is not.

// Retrieve user input
System.out.print(" Enter the total dollar amount of sales for this year.");
salesAmount=keyboard.nextDouble( );

if ( salesAmount >= 320000 ) {
    System.out.println( " Your total compensation for this year is " +
        ( 0.0925 * salesAmount + 30000 ));
  }

if ( salesAmount < 320000 ) {
    System.out.println( " Your total compensation for this year is " +
        ( 0.08 * salesAmount + 30000 ));
  }
}
  1. import java.util.Scanner; //needed to obtain user input
  2. public class AnnualPayCalculator
  3. {
  4. public static void main(String[ ] args)
  5. {
  6. double salesAmount ; //declare variables
  7. // Create Scanner object to obtain user input.
  8. Scanner keyboard = new Scanner(system(dot)in); ///I wrote (dot) here because it would not let me post because it was assuming this was a web address, which it is not.
  9. // Retrieve user input
  10. System.out.print(" Enter the total dollar amount of sales for this year.");
  11. salesAmount=keyboard.nextDouble( );
  12. if ( salesAmount >= 320000 ) {
  13.     System.out.println( " Your total compensation for this year is " +
  14.         ( 0.0925 * salesAmount + 30000 ));
  15.   }
  16. if ( salesAmount < 320000 ) {
  17.     System.out.println( " Your total compensation for this year is " +
  18.         ( 0.08 * salesAmount + 30000 ));
  19.   }
  20. }
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Posts: 371
  • Loc: Riverside, CA

Post 3+ Months Ago

Can you include the full program source code you are using? It's been several years since I took Java, but I think I can help. I can already see some problems. For example, your do while and if loops in the second code snippet of your first post are going to have syntax errors. No curly brackets, and seemingly random parenthesis among other things. I don't have a Java compiler but look at this code, it should help you get the idea..

Code: [ Select ]

int sum = 0;

    for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
    {
        sum += i;
        System.out.println(sum);

        //and

        do {

            if ( salesAmount >= 320000 ) {

                System.out.print( salesAmount * 0.925 );
            }

            if ( salesAmount < 320000 ) {

                System.out.print("Total Sales " + ( salesAmount * 0.08 ));
            }

        } while (salesAmount < salesAmount*1.5)

        system.out.print( salesAmount+=5000 )

        if (salesAmount < salesAmount*1.5 )
        {
            system.out.print("Total Compensation" + ( 0.8*salesAmount+30000 ));

            System.out.println("firstcolumn\tSecondColumn\tThirdColumn");
        }
    }
  1. int sum = 0;
  2.     for (int i = salesAmount; i <= salesAmount*1.5; i=+5000)
  3.     {
  4.         sum += i;
  5.         System.out.println(sum);
  6.         //and
  7.         do {
  8.             if ( salesAmount >= 320000 ) {
  9.                 System.out.print( salesAmount * 0.925 );
  10.             }
  11.             if ( salesAmount < 320000 ) {
  12.                 System.out.print("Total Sales " + ( salesAmount * 0.08 ));
  13.             }
  14.         } while (salesAmount < salesAmount*1.5)
  15.         system.out.print( salesAmount+=5000 )
  16.         if (salesAmount < salesAmount*1.5 )
  17.         {
  18.             system.out.print("Total Compensation" + ( 0.8*salesAmount+30000 ));
  19.             System.out.println("firstcolumn\tSecondColumn\tThirdColumn");
  20.         }
  21.     }



NOTE: I tried not to change your code, only change parenthesis to curly brackets, and add missing curly brackets/parenthesis..

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: Liamw411 and 136 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.