1 Replies - 2537 Views - Last Post: 20 January 2011 - 09:18 PM Rate Topic: -----

#1 Stewybaby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 27-August 10

Inventory Program

Posted 20 January 2011 - 09:03 PM

I have a homework assignment and I've tried to figure it out. I need help getting started. I don't know if I'm on the right track. Here is the assignment:

1) Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows:

Product 1 1 unit (cost is $2.98 per unit)
Product 2 2 units (cost is $4.50 per unit)
Product 3 3 units (cost is $9.98 per unit)
Product 4 4 units (cost is $4.49 per unit)
Product 5 5 units (cost is $6.87 per unit)

Your application must calculate and display the total retail value of all products sold, after all 5 pairs of inputs are completed. You must also display the total after each new pair of input values is entered.

This is what I have so far. Like I said I just need to be pointed in the right direction. I'm about to give up.
/**
 * @(#)StewartBaxterP3.java
 *
 * StewartBaxterP3 application
 *
 * @author
 * @version 1.00 2011/1/20
 */

import javax.swing.*;
import java.util.Scanner;

public class StewartBaxterP3
{
    public static void main(String[] args)
    	{
    		final int NUMBER_OF_ITEMS = 5;
    		int[] productNum = { 1, 2, 3, 4, 5};
    		double[] price = { 2.98, 4.50, 9.98, 4.49, 6.87};
    		double quantity, product, total;
    		Scanner imput = new Scanner(System.in);
    		System.out.print("Enter Product Number (1-5) or -1 to Quit:");
    		productNum = imput.nextInt();
    		System.out.print("Enter Quantity:");
    		quantity = imput.nextDouble();
    		total = product * quantity;
    		System.out.print(total);
    	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Program

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Inventory Program

Posted 20 January 2011 - 09:18 PM

Don't use parallel arrays. Design a Product class and store a Product[]. I go into more detail on class design in my tutorial Moving Away From Parallel Arrays.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1