Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE PROVIDE ALL NECESSARY JAVA SOURCE FILES. IT NEEDS TO BEAR WITH THE FIRST

ID: 3604609 • Letter: P

Question

PLEASE PROVIDE ALL NECESSARY JAVA SOURCE FILES. IT NEEDS TO BEAR WITH THE FIRST PART AND THEN FOLLOWED BY THE SECOND PART

Lab: Develop a program for an online store which sells dvds and books (items). The store will have a cart which will contain the items the user w an ts to purchase and their price The inventory for books and dvds will be stored in two separate string arrays which will contain the names of the books and the names of the dvds. In addition, two separate arrays of type double will be used to store the price corresponding to each item. You will create the arrays and populate them with data at the beginning of your program. This is how the arrays will look: books Intro to Java Intro to C++ hon Perl | C# booksPrices 45.99 89.34 100.00 25.0049.99 dvds Snow White Cinderella Dumbo Bambi Frozen dvdsPrices 19.99 24.99 17.99 21.9924.99 Moreover, you will implement the cart as two arrays too. The first array is for the names of the items the user wishes to purchase (books or dvds). The second is for the corresponding prices You can assume a maximum cart size of 5 items, i.e., the User cannot have more than 5 items in their cart. After you create and initialize all the arrays and array lists, the program will then display a menu for the user by calling the method displayMenu (). The method will display the following lines when called: **Welcome to the Comets Books and DVDs Store** Choose from the following options 1 - Browse books inventory (price low to high) 2 - Browse DVDs inventory (price low to high) 3 - Add a book to the cart 4 - Add a DVD to the cart 5 - View cart 6 - Checkout

Explanation / Answer

Here is the basic code for you:

import java.io.*;
import java.util.*;

class OnlineStore
{
    public static void displayMenu()
    {
       System.out.println("**Welcome to the Comets Books and DVSs Store**");
       System.out.println(" Choose from the following options:");
       System.out.println("1 - Browse books inventory (price low to high)");
       System.out.println("2 - Browse DVDs inventory (price low to high)");
       System.out.println("3 - Add a book to the cart");
       System.out.println("4 - Add a DVD to the cart");
       System.out.println("5 - View cart");
       System.out.println("6 - Checkout");
       System.out.println("7 - Cancel Order");
       System.out.println("8 - Exit store");
    }
    public static int[] sort(double[] prices)
    {
       int[] inventoryNumbers = new int[prices.length];
       for(int i = 0; i < prices.length; i++)
           inventoryNumbers[i] = i;
       for(int i = 0; i < prices.length-1; i++)
       {
          int small = i;
          for(int j = i; j < prices.length; j++)
              if(prices[inventoryNumbers[j]] < prices[inventoryNumbers[small]])
                  small = j;
          int temp = inventoryNumbers[small];
          inventoryNumbers[small] = inventoryNumbers[i];
          inventoryNumbers[i] = temp;      
       }  
             
       return inventoryNumbers;
    }
    public static void displayArrays(String[] itemsArray, double[] pricesArray, String itemType)
    {
       int[] inventoryNumbers = sort(pricesArray);
       for(int i = 0; i < pricesArray.length; i++)
           System.out.printf("%d %-20s $%3.2f ", inventoryNumbers[i]+1, itemsArray[inventoryNumbers[i]], pricesArray[inventoryNumbers[i]]);
    }
    public static int getInventoryNumber()
    {
       System.out.println("Enter the inventory number you wish to purchase (-1 to redisplay the menu.): ");
       Scanner sc = new Scanner(System.in);
       int inventoryNumber = sc.nextInt();
       return inventoryNumber;
    }
    public static void displayArrays(String[] cartItems, double[] cartPrices, int numOfItems)
    {
       for(int i = 0; i < numOfItems; i++)
           System.out.printf("%-20s $%3.2f ", cartItems[i], cartPrices[i]);
       System.out.printf("Total + tax $%4.2f ", getTotal(cartPrices, numOfItems));
    }
    public static double getTotal(double[] prices, int numOfItems)
    {
       double total = 0;
       for(int i = 0; i < numOfItems; i++)
           total += prices[i];
       return total * 1.0825;  
    }
    public static void clearArrays(String[] items, double[] prices, int numOfItems)
    {
       for(int i = 0; i < numOfItems; i++)
       {
          items[i] = null;
          prices[i] = 0;
       }     
    }
    public static void main(String[] args)
    {
       String[] books = {"Intro to Java", "Intro to C++", "Python", "Perl", "C++"};
       double[] bookPrices = {45.99, 89.34, 100.00, 25.00, 49.99};
      
       String[] dvds = {"Snow White", "Cinderella", "Dumbo", "Bambi", "Frozen"};
       double[] dvdsPrices = {19.99, 24.99, 17.99, 21.99, 24.99};
      
       String[] cartItems = new String[5];
       double[] cartPrices = new double[5];
       int numOfItems = 0, invNum;
      
       Scanner sc = new Scanner(System.in);
       int choice;
       while(true)
       {
          displayMenu();
          System.out.print("Enter your choice: ");
          choice = sc.nextInt();
          switch(choice)
          {
             case 1:       displayArrays(books, bookPrices, "Books");
                         break;
             case 2:       displayArrays(dvds, dvdsPrices, "DVDs");
                         break;
             case 3:       invNum = getInventoryNumber();
                         cartItems[numOfItems] = books[invNum-1];
                         cartPrices[numOfItems] = bookPrices[invNum-1];
                         numOfItems++;
                         break;
             case 4:       invNum = getInventoryNumber();
                         cartItems[numOfItems] = dvds[invNum-1];
                         cartPrices[numOfItems] = dvdsPrices[invNum-1];
                         numOfItems++;
                         break;
             case 5:       displayArrays(cartItems, cartPrices, numOfItems);
                         break;
             case 6:       displayArrays(cartItems, cartPrices, numOfItems);
                         clearArrays(cartItems, cartPrices, numOfItems);
                         numOfItems = 0;
                         break;
             case 7:       clearArrays(cartItems, cartPrices, numOfItems);
                         numOfItems = 0;
                         break;
             case 8:       return;
             default:   System.out.println("This option is not acceptable.");
          }
       }
    }
      
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote