Java Inventory Program 1-3

Only available on StudyMode
  • Download(s) : 219
  • Published : September 23, 2010
Open Document
Text Preview
Instructions: This document contains the tutorials for Inventory programs 1-3. These programs will be separated by pages between each program in addition to being color coded. NOTE: This information will need to be copy and pasted into a notepad document. For your own benefit, please do not plagiarize this work.

// Inventory program part 1 Inventory1.java
//
// A product class that stores and makes the name of the product, the item number, the number of units in stock, and the price of each unit retrievable. // Java app. that displays the product name, the item number, price of each unit, and the value of inventory.

import java.util.Scanner;
import java.text.NumberFormat;
import java.text.DecimalFormat;

class Product

{

private String name; // product name
private int number; // product part number
private double price; // product unit price
private int quantity; // products in stock

public Product(String N, int Num, double P, int Q) // Constructor
{
name = N;
number = Num;
price = P;
quantity = Q;
}

// Getters and setters
public void setName(String N) // method to set product name
{
name = N;
}

public String getName() // method to get product name
{
return name;
}

public void setNumber(int Num) // method to set part number
{
number = Num;
}

public int getNumber() // method to get part number
{
return number;
}

public void setPrice(double P) // method to set unit price
{
price = P;
}

public double getPrice() // method to get unit price
{
return price;
}

public void setQuantity(int Q) // method to set product quantity
{
quantity = Q;
}

public int getQuantity() // method to get product quantity
{
return quantity;
}

public double getTotalPrice() // return the total value of the inventory
{
double TotalPrice = quantity * price;
return TotalPrice;
}

} // End class product

public class Inventory1
{

// starts execution of Inventory program
public static void main(String args[])
{

// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);

// create NumberFormat to obtain input from command window NumberFormat currency = new DecimalFormat("\u00A4 #.00");

System.out.println(); // outputs a blank line
System.out.print("Enter the name of the product: "); // prompt for name of product
String N = input.nextLine(); // read product name from user
System.out.println(); // outputs a blank line

System.out.println(); // outputs a blank line
System.out.print("Enter the product number for the product: "); // prompt for product number
int Num = input.nextInt(); // read product number from user
System.out.println(); // outputs a blank line

System.out.println(); // outputs a blank line
System.out.print("Enter the unit price for the product: $ "); // prompt for unit price
double P = input.nextDouble(); //read product unit price from user
System.out.println(); // outputs a blank line

System.out.println(); // outputs a blank line
System.out.print("Enter number of units of product in stock: "); // prompt for number of units in stock
int Q = input.nextInt(); // read number of units in stock
System.out.println(); // outputs a blank line

double TotalPrice = Q * P;

System.out.println(); // outputs a blank line
System.out.println("Product name: "+ N);
System.out.println(); // outputs blank line
System.out.println("Product number: " + Num);
System.out.println(); // outputs blank line
System.out.println("Product's unit price: " + currency.format(P));
System.out.println(); // outputs blank line
System.out.println("The value of the inventory is " + currency.format(TotalPrice));

} // End method main

} // End class Inventory1

// Inventory program part 2 Inventory2.java
//
//...
tracking img