# Can someone describe how you can manipulate one user's input and placing it in a table?

Michael Gilliard
Greenhorn
Posts: 3

The above code compiled correctly and is working.
this is where I get lost. I need a table to be created,
populated with the user's original sales amount, and
commission earned for that amount + the annual salary.
As if this isn't difficult enough, I also need the
table to be populated with figures created by
increasing the original sales amount in increments of
5000 until the amount is greater than or equal to
1.5 * times the original sales amount. There must also be
a commission total + annual salary for each amount.

Winston Gutkowski
Bartender
Posts: 10527
64
Michael Gilliard wrote:The above code compiled correctly and is working. this is where I get lost. I need a table to be created, populated with the user's original sales amount, and commission earned for that amount + the annual salary. As if this isn't difficult enough, I also need the table to be populated with figures created by increasing the original sales amount in increments of 5000 until the amount is greater than or equal to 1.5 * times the original sales amount. There must also be a commission total + annual salary for each amount.

This sounds like a homework problem, so it might be good for you to give us the exact wording of the problem, because your description is a bit confusing.

Also, don't expect anyone here to simply hand you the answer (and if they do, it will be removed).

What exactly is it you're having problems with? Do you not know how to create a table? Or do you not know how to do what's been asked for?

A few tips:
• Break down the problem into single issues and deal with them one at a a time.
• What is this "table" supposed to be? An array? A List? If you're not sure, ask your tutor what they wanted - nothing wrong with that.
• Get out a pencil and paper and write down what you think needs to be done in English. You'll never solve a problem by simply coding.

• But whatever you do, try something out first, and then come back if you're still having problems. People will be much more willing to help you if you ShowSomeEffort (←click).

Winston

Michael Gilliard
Greenhorn
Posts: 3
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.

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:
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.

Campbell Ritchie
Sheriff
Posts: 50278
80
That code looks as if you are guessing. What you need to do is write it down carefully in English, like this
• 1: If he sells over \$40000 he gets 0.08 commission
• 2: If he sells over 100% of his target, his commission is increased to 1.25 × [old commission]
• etc etc.
Don’t even try to draw a table until after you have worked out the arithmetic.

The once you have got that lot written simplky, you will find it easy to change to code. Get a copy of Code Complete by Stephen ?McConnell? and he describes that, calling it the pseudo‑code process.

Michael Gilliard
Greenhorn
Posts: 3
Thank you for your help. I was beginning to think I'd never figure this out and all along it was as simple as breaking the situation down into plain language and learning some of the formatting rules. I'm still no pro, but now I feel much more comfortable with programming. Thanks again for all of your help.

Campbell Ritchie
Sheriff
Posts: 50278
80
Well done Show us what you have got so far.

Winston Gutkowski
Bartender
Posts: 10527
64
Michael Gilliard wrote:Here is the table I created, but it will not work for this program...

OK, a bit more general advice:
A JTable is a visual representation of a table, NOT the table itself - which, as you said, can be an array, List or whatever. It is, however, according to the docs, a two-dimenional grid, so whatever backing object you use better qualify.

At the risk of repeating previous advice, don't worry about the JTable. In fact: don't worry about the GUI at all. The question, as listed, is 90% LOGIC, so concentrate on creating a 2D data store and filling it/updating it with the correct values.

Only when you're absolutely sure that you've got it working correctly should you even consider plugging it into a JTable.

Displaying results is a completely different thing from solving a problem, so only worry about it when you're sure that you have solved the problem; otherwise you'll be forever distracted by display issues.

Winston

Edward Wright
Greenhorn
Posts: 11
At the risk of repeating previous advice, don't worry about the JTable. In fact: don't worry about the GUI at all. The question, as listed, is 90% LOGIC, so concentrate on creating a 2D data store and filling it/updating it with the correct values.
Winston

I'm assuming when you say 2d data store you are referring to a two dimensional array?