Please need this program done ASAP use comments and exceptio
Please need this program done ASAP use comments and exceptions and inheritance. do not use stacks!! and Additional Packages that are not needed!!
Solution
public interface Retail {
double RetailCost();
double AverageCost();
double TotalCost();
int TotalItems();
}
import java.util.ArrayList;
class ShoppingBag implements Retail
{
private double taxrate=0;
private int totalitems=0;
private double retailcost=0;
ArrayList<Double> itemlist =new ArrayList<Double>();
public ShoppingBag(double taxrate)
{
this.taxrate=taxrate;
}
public double RetailCost() {
// TODO Auto-generated method stub
retailcost=0;
for(int i=0;i<itemlist.size();i++)
{
retailcost=retailcost+itemlist.get(i);
}
return retailcost;
}
public double AverageCost() {
// TODO Auto-generated method stub
double averagecost=RetailCost()/itemlist.size();
return averagecost;
}
public double TotalCost() {
// TODO Auto-generated method stub
double totalcost;
totalcost=RetailCost() + (taxrate/100)*RetailCost();
return totalcost;
}
public int TotalItems() {
// TODO Auto-generated method stub
return totalitems=itemlist.size();
}
public void Buy(int quantity,double price)
{
for(int i=0;i<quantity;i++)
{
itemlist.add(price);
}
}
public double getTaxrate()
{
return taxrate;
}
public String toString()
{
return String.format(\"Items : \"+this.TotalItems()+ \".%n \"+\"RetailCost : \"+this.RetailCost() +\".%n\" +\" Average Item Cost : \"+this.AverageCost()+\".%n\"+\"Total cost including tax\"+\"(\"+this.getTaxrate()+\"): \"+this.TotalCost());
// .%n is for new line
}
public static void main(String args[])
{
ShoppingBag a=new ShoppingBag(10);
a.Buy(10, 10);
System.out.println(a);
}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class FileApp {
public static void main(String args[])
{ int errorcount=0;
ShoppingBag mybag=new ShoppingBag(7);
Scanner data; // Character input stream for reading data.
try { // Create the input stream.
data = new Scanner(new FileReader(\"data.dat\"));
}
catch (FileNotFoundException e) {
System.out.println(\"Can\'t find file data.dat!\");
return; // End the program by returning from main().
}
// Read numbers from the input file
int quantity=0;
double price=0;
while (data.hasNext()) { // Read until end-of-file.
try {
IOException e = new IOException();
if(data.hasNextInt())
{
quantity = data.nextInt();
if(data.hasNextDouble())
{
price=data.nextDouble();
}
else
{
throw e;
}
}
else
{
throw e;
}
mybag.Buy(quantity, price);
}//end of try block
catch (IOException e) {
// Some problem reading the data from the input file.
errorcount++;
}
}//end of while loop
// Finish by closing the files, whatever else may have happened.
data.close();
System.out.println(mybag.toString());
if(errorcount!=0)
{
System.out.println(+errorcount+ \"input mismatchs occurred\");
}
} // end of main()
}



