I want to Define class name MutiItemSale that represents a sale of multiple items of type Sale. The class MutiItemSale that have instance variable whose type is Sale[], which will be used as a partially filled array. There will also anther instance variable of type int that keep track of how much of this array is currently used . the exact detail on method and other instance variable.Use this class in program that obtains information for items of type sale and of type discountSale. And compute the total bill for the list of items sold.
the problem is i dont know how to write multiemsale class that take sale array . so please help. thank
this part of mycod ..........................................................
public class Sale
{
private String name; //A nonempty string
private double price; //nonnegative
public Sale( )
{
name = "No name yet";
price = 0;
}
/**
Precondition: theName is a nonempty string; thePrice is nonnegative.
*/
public Sale(String theName, double thePrice)
{
setName(theName);
setPrice(thePrice);
}
public Sale(Sale originalObject)
{
if (originalObject == null)
{
System.out.println("Error: null Sale object.");
System.exit(0);
}
//else
name = originalObject.name;
price = originalObject.price;
}
public static void announcement( )
{
System.out.println("This is the Sale class.");
}
public double getPrice( )
{
return price;
}
public void setPrice(double newPrice)
{
if (newPrice >= 0)
price = newPrice;
else
{
System.out.println("Error: Negative price.");
System.exit(0);
}
}
public String getName( )
{
return name;
}
/**
Precondition: newName is a nonempty string.
*/
public void setName(String newName)
{
if (newName != null && newName != "")
name = newName;
else
{
System.out.println("Error: Improper name value.");
System.exit(0);
}
}
public String toString( )
{
return (name + " Price and total cost = $" + price);
}
public double bill( )
{
return price;
}
/*
Returns true if the names are the same and the bill for the calling
object is equal to the bill for otherSale; otherwise returns false.
Also returns false if otherObject is null.
*/
public boolean equalDeals(Sale otherSale)
{
if (otherSale == null)
return false;
else
return (name.equals(otherSale.name)
&& bill( ) == otherSale.bill( ));
}
/*
Returns true if the bill for the calling object is less
than the bill for otherSale; otherwise returns false.
*/
public boolean lessThan (Sale otherSale)
{
if (otherSale == null)
{
System.out.println("Error: null Sale object.");
System.exit(0);
}
//else
return (bill( ) < otherSale.bill( ));
}
public boolean equals(Object otherObject)
{
if (otherObject == null)
return false;
else if (getClass( ) != otherObject.getClass( ))
return false;
else
{
Sale otherSale = (Sale)otherObject;
return (name.equals(otherSale.name)
&& (price == otherSale.price));
}
}
public Sale clone( )
{
return new Sale(this );
}
}
------------------ and discountclass
public class DiscountSale extends Sale
{
private double discount;
public DiscountSale( )
{
super( );
discount = 0;
}
/**
Precondition: theName is a nonempty string; thePrice is nonnegative;
theDiscount is expressed as a percent of the price and is nonnegative.
*/
public DiscountSale(String theName,
double thePrice, double theDiscount)
{
super(theName, thePrice);
setDiscount(theDiscount);
}
public DiscountSale(DiscountSale originalObject)
{
super(originalObject);
discount = originalObject.discount;
}
public static void announcement( )
{
System.out.println("This is the DiscountSale class.");
}
public double bill( )
{
double fraction = discount/100;
return (1 - fraction)*getPrice( );
}
public double getDiscount( )
{
return discount;
}
/**
Precondition: Discount is nonnegative.
*/
public void setDiscount(double newDiscount)
{
if (newDiscount >= 0)
discount = newDiscount;
else
{
System.out.println("Error: Negative discount.");
System.exit(0);
}
}
public String toString( )
{
return (getName( ) + " Price = $" + getPrice( )
+ " Discount = " + discount + "%\n"
+ " Total cost = $" + bill( ));
}
public boolean equals(Object otherObject)
{
if (otherObject == null)
return false;
else if (getClass( ) != otherObject.getClass( ))
return false;
else
{
DiscountSale otherDiscountSale =
(DiscountSale)otherObject;
return (super.equals(otherDiscountSale)
&& discount == otherDiscountSale.discount);
}
}
public DiscountSale clone( )
{
return new DiscountSale(this );
}
}