DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Tracking Sales

  1. #1
    Join Date
    Nov 2006

    Tracking Sales

    I have wrote my code, but I needs some help with it. Could somebody please help me with this. Thanks.

    Write a Sales program that prompts for and reads in the sales for each of 5 salespeople in a company. 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. Compute and print the average sale. (You can compute this directly from the total; no loop is necessary.)
    2. 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 need another loop for this; you can do it in the same
    loop where the values are read and the sum is computed.
    3. Do the same for the minimum sale.
    4. 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. 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. Instead of always reading in 5 sales amounts, at the beginning ask the user for the number of sales people and then create
    an array that is just the right size. The program can then proceed as before.

    // Sales.java
    // Reads in and stores sales for each of 5 salespeople. Displays
    // sales entered by salesperson id and total sales for all salespeople.
    // ****************************************************************
    import java.util.Scanner;

    public class Sales
    public static void main(String[] args)
    final int SALESPEOPLE = 5;
    int[] sales = new int[SALESPEOPLE];
    int sum;
    int max;
    int avg;
    int min;

    Scanner scan = new Scanner(System.in);

    for (int i=0; i<sales.length; i++)
    System.out.print("Enter sales for salesperson " + i + ": ");
    sales[i] = scan.nextInt();
    if (sales[i] > max) {
    max = sales[i];
    maximum = i;
    if (minSet) {
    if (sales[i] < min)
    min = sales[i];
    minimum = (i+1);
    else {
    min = sales[i];
    minimum = (i+1);
    minSet = true;


    System.out.println("\nSalesperson Sales");
    sum = 0;
    for (int i=0; i<sales.length; i++)
    System.out.println(" " + i + " " + sales[i]);
    sum += sales[i];
    average = sum/SALESPEOPLE;


    System.out.println("\nTotal sales: " + sum);
    System.out.println("\nSalesperson " + minimum + " scored the low sale of $" + min);
    System.out.println("\nSalesperson " + maximum + " scored the high sale of $" + max);
    System.out.println("\nAverage sale: " + average);


  2. #2
    Join Date
    Aug 2006
    STL, MO, USA
    Ummm... you have the code sales.length in there, yet you don't define it...

  3. #3
    Join Date
    Dec 2004
    San Bernardino County, California

    What kind of help are you looking for? Are you able to compile your code? Are you receiving run time error messages?

    Your design is a straight procedural design - along the lines of a c program - and not an OOP oriented Java design. Think of the way you will construct an instance of your class, provide data fields for your class, and methods to calculate values or manipulate your input and format and print your output. Don't dump everything into main(). The purpose of main() in a Java class is to take and pass arguments from the command line, instantiate class object(s), and to drive the functioning of the class. In many ways you should think of it as sitting "outside" (or on the interface) of the class, passing commands into the "black box" of the class object for you.

    Initialize values for your int variables - make avg = 0, sum = 0, max = 0, min = some number well beyond a value you would expect for the largest of sales. You need to assure yourself that your program will enter your if sales[i] > max and if sales[i] < min loops at least once. That first assignment is crucial!

    length is a field for each array which holds/reports the dimension of the array (not how many elements are actually in use)

Similar Threads

  1. session tracking problem
    By yuvrajsurvase in forum Java
    Replies: 0
    Last Post: 06-01-2006, 09:02 AM
  2. Bug/Issue Tracking Software
    By hominamad in forum ASP.NET
    Replies: 1
    Last Post: 05-10-2005, 11:27 PM
  3. Event Tracking System
    By Joe in forum Architecture and Design
    Replies: 0
    Last Post: 09-06-2002, 02:12 PM
  4. New software company
    By Ray Cassick \(home\) in forum Careers
    Replies: 3
    Last Post: 09-02-2002, 02:32 AM
  5. Text spacing aka tracking
    By Gavin in forum .NET
    Replies: 0
    Last Post: 07-13-2002, 06:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.