Trouble with manipulating user input and placing in a table.
- Basic Chaos
- Born


- Joined: Oct 26, 2012
- Posts: 2
- Status: Offline
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.
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);
}
}
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:
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.
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);
}
}
- 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);
- }
- }
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");
}
}
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");
}
}
- 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");
- }
- }
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


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
October 26th, 2012, 7:28 am
- Basic Chaos
- Born


- Joined: Oct 26, 2012
- Posts: 2
- Status: Offline
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 ));
}
}
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 ));
}
}
- 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 ));
- }
- }
- Hacker007
- Proficient


- Joined: Apr 07, 2004
- Posts: 371
- Loc: Riverside, CA
- Status: Offline
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..
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");
}
}
NOTE: I tried not to change your code, only change parenthesis to curly brackets, and add missing curly brackets/parenthesis..
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");
}
}
- 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");
- }
- }
NOTE: I tried not to change your code, only change parenthesis to curly brackets, and add missing curly brackets/parenthesis..
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." -Martin Golding
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 174 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
