Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee.
package InventoryProgram;
public class Main {
public static void main(String[] args) {
Product dvd = new Product ("Bye Bye Love", 1, 19.99, 3);
System.out.println(dvd);
dvd = new Product ("Fireside Rflections", 2, 12.99, 5);
System.out.println(dvd);
dvd = new Product ("Green Mile", 3, 24.99, 2);
System.out.println(dvd);
dvd = new Product ("Titanic", 4, 30.00, 10);
System.out.println(dvd);
System.out.println("Product Title is: " + dvd.getDvdTitle());
System.out.println(" The item number is: " + dvd.getDvdItemNumber());
System.out.println("The price of each DVD is $ " + dvd.getDvdPrice());
System.out.println(" The number of units in stock is: "
+ dvd.getDvdStockNumber());
}//end main class
}//end Inventory Program Part 1
package inventoryprogram;
import InventoryProgram.Product;
public class DVD extends Product {
//Inherites class DVD from the base class Product, the extra feature is having
//a year the movie was made.
private int movieyear;
//Holds the year the movie was made
public DVD(String title, int itemNumber, double price, int stockNumber, int year){
//Constructor to call the Product constructor.
super (title, itemNumber, price, stockNumber);
movieyear = year;
}
public void setYear(int year){
//Sets year
movieyear = year;
}
public int getYear(){//get the year of the DVD product
return movieyear;
}
public double getValue(){
return super.Value()* 1.05;
}//Overrides Value() in Product class by calling the base class and adding a
//5% restocking fee on top
public double getRestockingFee() {
return super.Value() * .05;
}//gets the base class value and figures out the restocking fee only
}
package InventoryProgram;
import java.text.DecimalFormat;
//Import the format class to format values into currency format
public class Inventory {
int inventorySize = 30;
//This sets the Array to hold "30" items
private Product items [] = new Product [inventorySize];
DecimalFormat formatter = new DecimalFormat ("$##,###.00");
//Sets the formatter to format values into currency form
public void addDVD (Product item){
for (int i =0; i< inventorySize; i++){
if (items [i] == null){
items [i] = item;
return;
}
}
}
// Loops through the array of products and adds up the total value.
// Adds the value to a running total accumulator variable.
public double getTotalInvValue(){
double Value = 0.0;
//Uses a comndensed for loop that iterates the array of items.
for (Product item : items){
if (item != null){
Value += item.getDvdPrice();
}
}
return Value;
}
//Prints the inventory list including name, quantity, price and total stock
//value for each item.
public void printInventory(){
System.out.println("Printing items in inventory...\n");
boolean DVDItems = false;
for (Product item : items){
if (item != null){
DVDItems = true;
System.out.println(item.getDvdTitle() + "Quantity: "
+ item.Value() + "Value of Stock: "
+ formatter.format(item.Value()));
}
}
}
}[code]
package InventoryProgram;
public class Main {
Public static void main(String[] args) {
Poduct dvd = new Product ("Bye Bye Love", 1, 19.99, 3);
System.out.println(dvd);
dvd = new Product ("Fireside Rflections", 2, 12.99, 5);
System.out.println(dvd);
dvd = new Product ("Green Mile", 3, 24.99, 2);
System.out.println(dvd);
dvd = new Product ("Titanic", 4, 30.00, 10);
System.out.println(dvd);
System.out.println("Product Title is: " + dvd.getDvdTitle());
System.out.println(" The item number is: " + dvd.getDvdItemNumber());
System.out.println("The price of each DVD is $ " + dvd.getDvdPrice());
System.out.println(" The number of units in stock is: "+ dvd.getDvdStockNumber());
}//end main class
}//end Inventory Program Part 1 package inventoryprogram;
import InventoryProgram.Product;
public class DVD extends Product {
//Inherites class DVD from the base class Product, the extra feature is having
//a year the movie was made.
private int movieyear;
//Holds the year the movie was made
public DVD(String title, int itemNumber, double price, int stockNumber, int year){
//Constructor to call the Product constructor.
super (title, itemNumber, price, stockNumber);
movieyear = year;
}
public void setYear(int year){
//Sets year
movieyear = year;
}
public int getYear(){
//get the year of the DVD product
return movieyear;
}
public double getValue(){
return super.Value()* 1.05;
}
//Overrides Value() in Product class by calling the base class and adding a
//5% restocking fee on top
public double getRestockingFee() {
return super.Value() * .05;
}
//gets the base class value and figures out the restocking fee only }
package InventoryProgram;
import java.text.DecimalFormat;
//Import the format class to format values into currency format public class Inventory
{
int inventorySize = 30;
//This sets the Array to hold "30" items
private Product items [] = new Product [inventorySize];
DecimalFormat formatter = new DecimalFormat ("$##,###.00");
//Sets the formatter to format values into currency form
public void addDVD (Product item){
for (int i =0; i< inventorySize; i++){
if (items [i] == null){
items [i] = item;
return;
}
}
}
// Loops through the array of products and adds up the total value.
// Adds the value to a running total accumulator variable.
public double getTotalInvValue(){
double Value = 0.0;
//Uses a comndensed for loop that iterates the array of items.
for (Product item : items){
if (item != null){
Value += item.getDvdPrice();
}
}
return Value;
}
//Prints the inventory list including name, quantity, price and total stock
//value for each item.
public void printInventory(){
System.out.println("Printing items in inventory...\n");
boolean DVDItems = false;
for (Product item : items){
if (item != null){
DVDItems = true;
System.out.println(item.getDvdTitle() + "Quantity: + item.Value() + "Value of Stock: " + formatter.format(item.Value()));
}
}
}
}
This post has been edited by Beachgirl029: 20 July 2009 - 09:26 AM

New Topic/Question
Reply




MultiQuote








|