computer science

profilew.2.a
jim.docx

Jim's Discount items:

 

A company is looking for a program that can help keep track of their inventory for an array of inventories. There are two types of inventory accounts ─ toys and clothes.

 

Implement the following classes and methods.

 

Inventory class:

 

Instance variable:

Invbalance

 

Received method ─ add the incoming inventory to the current balance.

 

Sold method ─ subtract the outgoing inventory from the current balance. Don’t allow the balance to go below zero. If the balance does go below zero, change the balance to zero.

 

Display method ─ This must be an abstract method.

 

Toys class:

 

No new instance variables.

 

toyssold method ─ subtract the amount sold from the current inventory.

 

display method ─ print the type of inventory, toys, and then the balance of inventory. Study the output for details.

 

Clothing class:

 

Instance variable:

Returnclothes – for every amount of clothing sold there is a percent that is returned

 

addReturns method ─ calculates the returns by multiplying the Returnclothes by the current amount of clothing sold. Add the returns to the amount of clothing.

 

display method ─ print the type of inventory, clothing, and then the balance of inventory.

 

Provide appropriate constructors and additional methods as necessary. Study the given main method and output for details. Hint: Don’t allow the inventory to go below zero. If the inventory does go below zero, change the inventory to zero.

 

Provide a driver class that tests your three classes. Your driver class should contain this main method:

 

public static void main(String[] args)

{

  Inventory[] inventory = new Inventory[200];

 

  inventory[0] = new Clothing(500);

  inventory[0].received(100);

  inventory[0].sold(200, .05);

  ((Clothing) inventory[0]).addReturns();

 

  inventory[1] = new Toys(-100);

  inventory[1].received(50);

 

  inventory[2] = new Toys(200);

  inventory[2].sold(210);

  inventory[2].received(100);

  ((Toys) inventory[2]).toyssold(75);

   

  for (int i=0; i<inventory.length && inventory[i] != null; i++)

  {

    inventory[i].display();

  }

} // end main

 

Output:

 

Clothing Inventory = 410

Toys Inventory = 50

Toys Inventory = 25