Java Inventory Program 1-3

Did you like this example?

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. mport 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; } ublic 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; eturn 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. rintln(); // 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 // // Uses a method to calculate the value of the entire inventory // Uses another method to sort the array items by the name of the product // Output displays all product information as well as value of entire inventory import java. util. *; import java. text. NumberFormat; import java. text. DecimalFormat; class Product implements Comparable { rivate String name; // class variable that stores the item name private int number; // class variable that stores the item number private int quantity; // class variable that stores the quantity in stock private double price; // class variable that stores the item price public Product(String N, int Num, int Q, double P) // Constructor for the Supplies class { name = N; number = Num; quantity = Q; price = P; } // 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; } ublic 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 calculateInventoryValue() // method to calculate the value of the inventory { return price * quantity; } // sorts Products by their product name. ublic int compareTo (Object o) { Product s = (Product)o; return name. compareTo(s. getName()); } public String toString() // returns a string representation of the product information { System. out. println(); return “Name: “+name+ ” Number: “+number+” Price: $ “+ price +” Quantity: “+quantity+ ” Value: $ “+calculateInventoryValue(); } } // End class product public class Inventory2 { // main methods begins execution of java application public static void main( String args[]) { Product[] supplies = new Product[6]; // create array of office supllies // inventory of office supplies Product p1 = new Product(“Pens”, 1, 76, . 5); Product p2 = new Product(“Markers”, 2, 43, 1. 00); Product p3 = new Product(“White-out”, 3, 17, 2. 00); Product p4 = new Product(“Pencils”, 4, 91, . 15); Product p5 = new Product(“Crayons”, 5, 62, . 99); Product p6 = new Product(“Paint Set”, 6, 12, 19. 99); supplies[0] = p1; supplies[1] = p2; supplies[2] = p3; supplies[3] = p4; supplies[4] = p5; supplies[5] = p6; double total = 0. 0; for(int i= 0; i < 6;i++) { total = total + supplies[i]. calculateInventoryValue(); } // Display the total value of the inventory on the screen System. out. printf(“Total value of the entire inventory is: $ %. f”, total); System. out. println(); Arrays. sort(supplies); for(Product s: supplies) { System. out. println(s); System. out. println(); } } // end main method }//end class Inventory2 //Inventory Program Part 3 Inventory3. java // //Uses a subclass that adds an additional feature //Uses a method in the subclass to calculate the value of the inventory and adds a 5% restocking fee //to the value of each product //Displays output, sorted by name, including additional feature and 5% restocking fee class Inventory { String number; //stores product number String name; //stores product name nt quantity; //stores quanity in stock double price; //stores product price double restockFee; //stores product restocking fee public Inventory(String Num, String N, int Q, double P, double F) { name = N; number = Num; quantity = Q; price = P; restockFee = F; } public void setName(String N) //Method to set and get the product name { name = N; } public String getName() { return name; } public void setNumber(String Num) //Method to set and get the product number { number = Num; } public String getNumber() { return number; } public void setQuantity(int Q) //Method to set and get the quantity in stock { quantity = Q; public int getQuantity() { return quantity; } public void setPrice(double P) //Method to set and get the price of product { price = P; } public double getPrice() { return price; } public void setRestockFee(double F) //Method to set and get the product restocking fee { restockFee = F; } public double getRestockFee() { return restockFee; } public double getInventoryValue() //Method to calculate the value of the in stock inventory { return price * quantity; } public static double getTotalValueOfAllInventory(Inventory [] inv) { double tot = 0. 00; for(int i = 0; i < inv. length; i++) { tot += inv[i]. etInventoryValue(); } return tot; } public String toString() { return “Product Name: “+name + ” Product Number: “+number+” Product Price: $”+price+” Quantity in Stock: “+quantity + ” Inventory Value: $”+getInventoryValue(); } } // end Inventory Class class Product extends Inventory { String brand;// Subclass to add the product’s name brand double restockFee;// Restock fee to add to the inventory value // initialize constructor public Product(String brand, double restockFee, String Num, String N, int Q, double P, double F) { super(Num, N, Q, P, F); this. brand = brand; this. restockFee = restockFee; } ublic double getInventoryValue() // Figures total inventory value including restocking fee { return super. getInventoryValue() + (super. getInventoryValue() * restockFee); } public String toString() { StringBuffer sb = new StringBuffer(” Brand: “). append(brand). append(” “); sb. append(super. toString()); return sb. toString(); } } // End Product Class public class Inventory3 { public static void main(String args[]) { double restockFee = 0. 05; Product[] inventory = new Product[6]; //create array of Office Supplies inventory[0] = new Product(“Gel Glide” , restockFee, “1”,”Rollerball Pens” , 26, 1. 00, . 5 ); inventory[1] = new Product(“Sharpie” , restockFee, “2”,”Markers” , 23, 2. 00, 0. 10 ); inventory[2] = new Product(“Bic”, restockFee, “3”,”White-out”, 7, 3. 00, . 15); inventory[3] = new Product(“Generic”, restockFee,”4″,”Lead Pencils” , 12, 4. 00, . 20); inventory[4] = new Product(“Crayola”, restockFee, “5”, “Crayons”, 12, 5. 00, . 25); inventory[5] = new Product(“Rose Art”, restockFee, “6”, “Paint Set”, 12, 6. 00, . 30); Product temp[] = new Product[1]; System. out. print( ” Thank you for using Office Supply Inventory Program ” ); // display title System. out. println(); System. ut. println(); // Sorting the Inventory Information for(int j = 0; j < inventory. length – 1; j++) { for(int k = 0; k < inventory. length – 1; k++) { if(inventory[k]. getName(). compareToIgnoreCase(inventory[k+1]. getName()) > 0) { temp[0] = inventory[k]; inventory[k] = inventory[k+1]; inventory[k+1] = temp[0]; } } } // Print the Inventory Information for(int j = 0; j < inventory. length; j++) { System. out. println(inventory[j]. toString()); } System. out. printf(” Total inventory value: $%. 2f ” , Inventory. getTotalValueOfAllInventory(inventory)); return; } } // End Inventory3 Class

Don’t waste time! Our writers will create an original "Java Inventory Program 1-3" essay for you

Create order

Having doubts about how to write your paper correctly?

Our editors will help you fix any mistakes and get an A+!

Get started
Leave your email and we will send a sample to you.
Thank you!

We will send an essay sample to you in 2 Hours. If you need help faster you can always use our custom writing service.

Get help with my paper
Sorry, but copying text is forbidden on this website. You can leave an email and we will send it to you.