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!!

Here are some sample runs 1. You rolled 5 6 11 You win! 2. You rolled 1 2 3 You lose 3. You rolled 4 +4 8 Point is 8 You rolled 5 1 6 You rolled 3 2 5 You rolled 6 2 8 You win! 4. You rolled 3 2 5 Point is 5 You rolled 3 1 4 You rolled 2 5 7 You lose! Total wins-2 Total losses 2 2. Write a class called ShoppingBag to keep track of items purchased. The ShoppingBag contains a summary of an order. It will implement the Retail interface (given below) and will need some additional methods to place items in the bag and to output the bag\'s current status. ShoppingBag contains the total cost of items purchased (before tax), the total after tax, the number of items in the bag, and the average cost of an item Create the following interface and use it when implementing the ShoppingBag class. A. a. public interface Retail double RetailCost0; total cost of all items before tax double AverageCost0; ll average cost of an item, before tax total cost of all items including tax double TotalCost0; ll number of items in the bag int Total Items0; B. Create a class called Sho that the Retail interface. ofthis class represent a single shopping bag. Attributes of such an object include the number of items in the bag, the tax rate and the retail cost of those items. a. Create a constructor that accepts a tax rate as a double argument. b. create a method called Buy that puts an item the bag. It accepts an in argument indicating the quantity purchased and a double argument that indicates the cost of the item. For example myBag.Buy(5, 10.50 represents buying five items that cost 10.50 each.

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()

  
   }

 Please need this program done ASAP use comments and exceptions and inheritance. do not use stacks!! and Additional Packages that are not needed!! Here are some
 Please need this program done ASAP use comments and exceptions and inheritance. do not use stacks!! and Additional Packages that are not needed!! Here are some
 Please need this program done ASAP use comments and exceptions and inheritance. do not use stacks!! and Additional Packages that are not needed!! Here are some
 Please need this program done ASAP use comments and exceptions and inheritance. do not use stacks!! and Additional Packages that are not needed!! Here are some

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site