Hello everyone,
This is my first post to this forum and I am hoping someone out there can help me. I am an online student and the teachers are never available to help students on the weekend. I have been working steadily on an assignment form my Java class for the past 5 days. This assignment is due tomorrow 7/28/08. Below is the requirements of the assignment:
Modify the Inventory Program by creating a subclass of the product class that uses one
additional unique feature of the product you chose (for the DVDs subclass, you could use
movie title, for example). In the subclass, create a method to calculate the value of the
inventory of a product with the same name as the method previously created for the
product class. The subclass method should also add a 5% restocking fee to the value of
the inventory of that product.
· Modify the output to display this additional feature you have chosen and the restocking
fee.
My problem is that the new feature and restocking fee do not display when the program compiles. Can anyone please help me figure this out? Thanks in advance!
Here is my program:
// 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, "Ampad" );
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()
} // end class manufacturer