Loops and Arrays help

Hi,

I'm a freshman in college and new to java. I am completely lost and really need help with a current assignment. Here are the instructions given by my teacher...

Building on provided code:

Loops and Arrays

Tracking Sales

Files Main.java and Sales.java contain a Java application that prompts for and reads in the sales for each of 5 salespeople in a company. Files Main.java and Sales.java can be found here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Main.java

and here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Sales.java It then prints out the id and amount of sales for each salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:

1. (1 pts) Compute and print the average sale. (You can compute this directly from the total; no new loop is necessary.)

2. (2 pts) Find and print the maximum sale. Print both the id of the salesperson with the max sale and the amount of the sale, e.g., "Salesperson 3 had the highest sale with $4500." Note that you don't necessarily need another loop for this; you can get it in the same loop where the values are read and the sum is computed.

3. (2 pts) Do the same for the minimum sale.

4. (6 pts) After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the id of each salesperson who exceeded that amount, and the amount of their sales. Also print the total number of salespeople whose sales exceeded the value entered.

5. (2 pts) The salespeople are objecting to having an id of 0-no one wants that designation. Modify your program so that the ids run from 1-5 instead of 0-4. Do not modify the array-just make the information for salesperson 1 reside in array location 0, and so on.

6. (8 pts) Instead of always reading in 5 sales amounts, allow the user to provide the number of sales people and then create an array that is just the right size. The program can then proceed as before. You should do this two ways:

1. at the beginning ask the user (via a prompt) for the number of sales people and then create the new array

2. you should also allow the user to input this as a program argument (which indicates a new Constructor and hence changes to both Main and Sales). You may want to see some notes.

7. (4 pts) Create javadocs and an object model for the lab

You should organize your code so that it is easily readable and provides appropriate methods for appropriate tasks. Generally, variables should have local (method) scope if not needed by multiple methods. If many methods need a variable, it should be an Instance Variable so you do not have to pass it around to methods.

You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this.

I'm not asking for someone to do this assignment for me...I'm just hoping there is someone out there patient and kind enough to maybe give me a step by step of what to do or how to get started, because I am completely lost from the beginning of #1 in the instructions.

Any help would be much appreciated! Thank you!

Message was edited by:

Scott_010

Message was edited by:

Scott_010

[3507 byte] By [Scott_010a] at [2007-11-27 1:14:00]
# 1
Until you get started, we can't "help". Post a question/problem and a SMALL amount of code that illustrates it.
ChuckBinga at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 2
Well I don't even know how to compute and print the average sale...how would I go about doing that?
Scott_010a at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 3
> Well I don't even know how to compute and print the> average sale...how would I go about doing that?Given the total sales of 5 salesmen, you don't know how tocompute the average? Not even with a paper and pencil?
DrLaszloJamfa at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 4
The initial step is to understand the given code, Sales.java and Main.java.Make sure you understand what is being done there. If you don't understandit, ask a specific question about specific line(s) of code.
DrLaszloJamfa at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 5
Wouldn't it be 2.5?
Scott_010a at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 6

First ask the person who gave this asignment as to why do you require two classes for this , you can have only the Sales.java class with main method in it . Anyways.

Let Main.java have a main method which instanciates a public class Sales and calls a method named say readVal() in Sales class.

In the readVal method of sales class define two arrays i.e ids and sales. Start prompting the user for inputting the id and sales and with user inputting values keep storing it in the respective arrays .. Limit this reading to just 5 i.e only 5 salesPerson.

Once both the arrays are populated, call another method of Sales class which will be used for all computations and output passing both the arrays.

In this new method say Compute() , read values from array and keep calculating total,average and whatever you want by adding steps in just this loop. You can do this in readval method too after reading the values but lets keep the calculation part seperate from input.

>>You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this.

I think this is ur personal stuff , but if you want to use web page , you probably will require to use servlet to read values from the html form passed to the server.

Rohan.Desaia at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 7
Thank you Rohan.
Scott_010a at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 8
Welcome , I hope you ask the question regarding the use of two clases to ur teacher ?Object oriented study can be misleaded if examples cannot be linked with real life scenarios ....
Rohan.Desaia at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 9
LoL, I'm in this kids class...
jamocamaca at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 10
> LoL, I'm in this kids class...Was he the one that never said a word in class?
DrLaszloJamfa at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 11
I don't know I never go either... :) J/K, I don't know the kids personally
jamocamaca at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 12

I do have a valid question about this assignment... when I first try to run the applet, at the top of the thread (Sales and Main), in Firefox, it doesn't load and says "Applet Sales Notinited", why is this? Is my html code not right? Don't I run the applet with <applet code="Sales.java"></applet>? Thanx in advance....

jamocamaca at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 13
I think you need "Sales.class".
CaptainMorgan08a at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 14
I meant to say <applet code="Sale.class"></applet> Not Sales.java... I know that...Message was edited by: jamocamac
jamocamaca at 2007-7-11 23:49:19 > top of Java-index,Java Essentials,New To Java...
# 15

So can anyone help me with the two files mentioned in the first post here? I wanted to know, when I first try to run the applet, at the top of the thread (Sales and Main), in Firefox, it doesn't load and says "Applet Sales Notinited", and in the java runtime environment console, it says to a lot of lines ..(unknown Source), why is this? Is my html code not right? Don't I run the applet with <applet code="Sales.class"></applet>? Thanx in advance....

Message was edited by:

jamocamac

jamocamaca at 2007-7-21 20:01:40 > top of Java-index,Java Essentials,New To Java...