View Single Post
  #9 (permalink)  
Old 07-27-2008, 07:12 AM
ljk8950 ljk8950 is offline
Member
 
Join Date: Jul 2008
Posts: 43
ljk8950 is on a distinguished road
Reply to Eranga
Eranga,

Thanks for the info. I am going to post my code again to see if it displays betters. Please let me know if I did it right. By the way, I am still looking for help with this code. If anyone out there can help me, I would very much appreciate it. Thank you!

Code:
// CheckPoint: InventoryProgramPart3.java // Week 6 // This program calculates inventory value import java.util.Scanner; import java.util.Arrays; public class InventoryProgramPart3 { // main method begins program execution public static void main(String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner( System.in ); // display a welcome message to the InventoryProgramPart3 user System.out.println( "Welcome to Inventory Program Part 3!" ); // office supplies supplies[] supplies = new supplies[100]; // an array of 100 supplies supplies notepads = new supplies( 4000, "notepads", 60, 2.75 ); supplies pencils = new supplies( 5000, "pencils", 75, 1.25 ); supplies folders = new supplies( 2000, "folders", 30, 4.75 ); supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 ); supplies markers = new supplies( 3000, "markers", 45, 3.50 ); // display the inventories one at a time envelopes.showInventory(); folders.showInventory(); markers.showInventory(); notepads.showInventory(); pencils.showInventory(); // sort supplies by name for ( int i = 0; i < args.length; i++ ) System.out.println( args[i] + ", " ); double array[] = { 78.75, 142.50, 157.50, 165.00, 93.75 }; double total = 0; // add each element's value to total for ( int counter = 0; counter < array.length; counter++) total += array[ counter ]; System.out.printf( "\nTotal inventory value is: $%.2f\n", total ); System.out.println( "\nThank you for using Inventory Program Part 3!\n" ); } // end method main } // end class InventoryProgramPart3 // Office Supplies class supplies { public int suppliesNumber; public String suppliesName = new String(); public int suppliesUnits; public double suppliesPrice; // set supplies number public void setSuppliesNumber( int number ) { this.suppliesNumber = number; } // end method set supplies number // return supplies number public int getSuppliesNumber() { return suppliesNumber; } // end method get supplies number // set supplies name public void setSuppliesName( String name ) { this.suppliesName = name; } // end method set supplies name // return supplies name public String getSuppliesName() { return suppliesName; } // end method get supplies name // set supplies in stock public void setSuppliesUnits( int units ) { this.suppliesUnits = units; } // end method set supplies units // return supplies units public int getSuppliesUnits() { return suppliesUnits; } // end method get supplies units // set supplies price public void setSuppliesPrice( double price ) { this.suppliesPrice = price; } // end method set supplies price // return supplies price public double getSuppliesPrice() { return suppliesPrice; } // end method get supplies price // calculate supplies inventory value public double getValue() { return suppliesUnits * suppliesPrice; } // end method supplies inventory value // four-argument constructor supplies( int number, String name, int units, double price ) { suppliesNumber = number; suppliesName = name; suppliesUnits = units; suppliesPrice = price; } // end four-argument constructor // display inventory public void showInventory() { System.out.println(); // outputs blank line System.out.println( "Product Number: "+suppliesNumber ); System.out.println( "Product Name: "+suppliesName ); System.out.println( "Number of Units: "+suppliesUnits ); System.out.printf( "Unit Price: $%.2f", suppliesPrice ); // value() method and display the value System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getValue() ); } // end display inventory } // end class supplies class manufacturer extends supplies { // holds the supplies manufacturer private String suppliesManufacturer; // five-argument constructor manufacturer( int number, String name, int units, double price, String manufacturer ) { super( number, name, units, price ); suppliesManufacturer = manufacturer; } // end five-argument constructor // set supplies manufacturer public void setManufacturer( String manufacturer ) { this.suppliesManufacturer = manufacturer; } // end method set supplies manufacturer // return supplies manufacturer public String getManufacturer() { return suppliesManufacturer; } // end method get supplies manufacturer // add 5% restocking fee public double getValue() { return super.getValue() * 1.05; } // end method return supplies manufacturer // calculate restocking fee public double getRestockingFee() { return super.getValue() * .05; } //end method calculate restocking fee //return String representation of suppliesManufacturer public String toString() { String formatString = "Manufacturer: %s"; formatString += "Restocking Fee: $%.2f"; formatString = String.format( formatString, suppliesManufacturer, super.getValue() * 0.05 ); return( formatString + super.toString() ); } // end toString() // display inventory public void showInventory() { super.showInventory(); System.out.println( toString() ); System.out.println( "Manufacturer: "+suppliesManufacturer ); // Display value plus restocking fee System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n", getRestockingFee() ); } // end method display inventory } // end class manufacturer
Reply With Quote