I am so stuck on this, I understand the comcept behind the array, but cannot make it past where I am. I have to have an array that compares at least 2 salespersons annual compensation (from previous work), calculates the lower to exceed the higher compensation, and asks for the name of the salespersons.
I have this much figured out:
Please use code tags when posting code. That makes it much easier to read. I've added them for you here.
Arrays don't compare things; they provide a place to store things, also known as a data structure. You'll need a method to do the comparison. It seems like you're handling the input right, though you're only storing the compensation value in the array. Maybe you want to define a Salesperson class that contains both a name and a compensation figure. Then you could have an array of Salesperson rather than int. After that, I'm not sure what you're trying to do. I run off the rails at, "calculates the lower to exceed the higher compensation". I just can't parse that at all.
Just to add to what Greg said, you should also try to avoid very long lines. They cause windowing problems. I've split yours up this time.
Also: any timetable is your problem. We're all volunteers here.
I think you'd be much better off creating a SalesPerson class. Then an array of them is as simple as:
SalesPerson salespeople = new SalesPerson; // for example
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
The point of the code is to take 2 salespersons base sales, add the compensationcalc method to it to get the compensation + accel factor (if qualifies), and then find out which one is higher then what needs to be added to the lower to make it higher (even) to the higher sales number. I am stuck on how to send the salesperson's sales, send it to the compensationcalc method (or call the method?) and then retrieve the data to display.
Winston good info on creating new class of salesperson, Thanks.
I would think that calculating compensation would involve data related to the sales person. For example sales target may be a fixed value now, but what if in the future, you want different sales people have different targets. Therefore, I'd probably get rid of the CommisionCalc class, and put the calculation directly into SalesPerson. One of the basic principles of object-oriented programing is that you should state your problem in plain English, then pick out the nouns to become classes and the verbs to become methods. CommisionCalc looks more like a verb to me.
You are defenitly correct and I will try to implement your suggestions, but for now the code is still not working. I am a very greenhorn, and this was supposed to be for one of my classes ( I am not asking for the answers, I already posted the original code to the class) I just wanted to see where I was messing up.
I needed to have:
salesperson annual salary = 74,000
sales target of 200,000
commission of 12% after 80% of sales target is achieved
acceleration factor of 1.25 added to total if meets 200,000
display a table of potential commission earnings up to 150% of sales in 5,000 increments
use an array to compare 2 salespeople, find out which one is higher and calculate the difference to add to the lower to meet or exceed the higher.
As you can see I am trying to understand what is needed and how to go about it. My code does calculate the commission, but does not display the table or utilize the array (which is covered in red in Netbeans IDE). I am stumped. any suggestions would be helpful. My class is over Tuesday, this is just for my knowledge to help me understand the work.
Simply saying "The code is not working" really gives us nothing to help you with. WHAT is not working? Does it compile? Does it run or does it crash? Does it give the wrong output? What output did you expect? What input did you give it?
Honestly, if this is really for your own benefit, I would say throw it all away, and start over. But do it right. For the first few hours, don't think in java, think in English. Literally, write down what your program needs to do. Break it apart into separate components. For example, how you get an input is COMPLETELY independent of what you do with the input. Regardless of whether you prompt the user, read it from a database, open a socket, or any other method, your methods/classes that USE it don't care.
When you do get to it, write your code in small chunks - I only write 2-3 lines at a time before i recompile and test. and I test the hell out of it each time.
I would probably write a method that takes an int as the sales amount, and calculates the compensation for that amount.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors