Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
public class Cart{
    //the inventory java

    ArrayList<Book> cartBooks = new ArrayList<>();
    ArrayList<Movie> cartMovies = new ArrayList<>();
    ArrayList<CD> cartDiscs = new ArrayList<>();
    public int total;

    public void addToCart(Book book) {
        cartBooks.add(book);

    }

    public void addToCart(CD disc) {
        cartDiscs.add(disc);

    }

    public void addToCart(Movie movie) {
        cartMovies.add(movie);

    }

    public float getTotalBookPrices() {
        for (Book thisBook : cartBooks) {
            total += thisBook.getPrice();
        }
        return total;
    }
     public float getTotalMoviePrices() {
        for (Movie thisMovie : cartMovies) {
            total += thisMovie.getPrice();
        }
        return total;
    }
      public float getTotalCDPrices() {
        for (CD thisCD : cartDiscs) {
            total += thisCD.getPrice();
        }
        return total;
    }
      public void resetTotal() {
          total = 0;
      }
}