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

=============================================================== NEED HELP WITH T

ID: 662682 • Letter: #

Question

===============================================================
NEED HELP WITH THIS JAVA PROJECT URGENTLY. PLEASE ANSWER THIS
===============================================================


Write a Java program that simulates a simple online shopping system. It has 2 part of the pragram, one is the program itself and the other is GUI for the program:
(Please include screenshots of the output )

First part:

Using the UML diagram below as a guide, design and implement a set of classes that define various types of reading material. These classes model reading material one would purchase. Include data values that describe various attributes of the material.

Create these class files:
--------------------------------------

ReadingMatter has three instance variables: title (type String), ISBN (type String of 13 characters) and price (type double). Include a constructor and get and set methods for these three instance variables. The class also has a toString( ) method to return a description of the reading matter.


Magazine includes an extra instance variable: editor (type String) with get and set methods for it. Also override toString( ) and content( ) methods to include Magazine?s editor details.

Book includes an extra instance variable: author (type ArrayList) with get and set methods for it. There may be more than one author so allow their names to be stored in an ArrayList. Also override toString( ) method to include Book?s author details.


TextBook includes extra instance variable answers (type boolean) with get and set methods for it. Also override toString( ) method to include TextBook details.


Novel includes extra instance variable characters (type ArrayList) with get and set methods for it. Also override toString( ) method to include all characters in the Novel.

                Populate your online shopping system with at least FOUR entries from each category, e.g., BOOK, MAGAZINE, TEXTBOOK, NOVEL. At the start of your program, you should read in a text file with the required information. The format of the text file will be:

BOOK
TITLE: ?This is book a?
ISBN: ?5978230012546?
PRICE: 56.99
AUTHOR: John Denon

MAGAZINE
TITLE: ?News?
ISBN: ?1154462600125?
PRICE: 7.50
EDITOR: "Stuart, Lagoon"

TEXTBOOK
TITLE: ?Java text book?
ISBN:?9699563285452?
PRICE: 159
AUTHOR: ?Dan, Newman?, ?Adam, Sandstone"
ANSWERS: true

NOVEL
TITLE: ?A Road To The Village?
ISBN: ?549556897K?
PRICE: 22.99
AUTHOR: ?Daniell, K.P.?
CHARACTERS: ?Ron Jerrard?, ?Billy Sun?, ?Sandra Newman?

Note: The words BOOK, MAGAZINE, TEXTBOOK, and NOVEL are always presented in capital letters. There is always a blank line between entries in the file. TITLE, ISBN, PRICE, AUTHOR ANSWERS, and EDITOR are always capitalised. After one of these words will be a ?:?, followed by a blank space followed by the required data.

Define a class ShoppingCart that emulates a shopping cart. Define a method addToCart( ) to add reading materials to the cart and update the total price instance variable. Note the buyer is able to select from a list of reading material from each category. Also define a toString( ) method which returns the contents of the cart together with the summary information of the items in it.
Create a main driver class entitled CheckOut that should have a loop to continue as long as the user wants to shop. After selecting the menu item the program should prompt the user to add reading material details. When the user finishes shopping, print the cart contents and ?Please pay?..? message with the total price of the items in the cart.

After a sale is completed, update a sales file (entitle: salesFile.txt) with the total purchase price from each of the four categories, as well as the date of the last sale. For example, if the file originally contains:

2009-09-09
BOOK: 1123.90
MAGAZINE: 145.67
TEXTBOOK: 2634.60
NOVEL: 573.20

And another sale was completed on 2009-09-10 for a novel costing $21.90, the file would now show:

2009-09-10
BOOK: 1123.90
MAGAZINE: 145.67
TEXTBOOK: 2634.60
NOVEL: 595.10

It should be possible to retrieve the information from the salesFile just prior to exiting the program.

Second part: GUI

Design an appropriate GUI application to set up and run the proposed OnLine Shopping System that would allow the customer to select the reading material of their choice.

NOTE: It is expected that you should not need to rewrite any of the classes from Part 1. Rather you will create instances of the relevant classes when you need them for Part 2.
The GUI for this program should create at least two new classes one being the JFrame for displaying the GUI JPanel, and the GUI JPanel with its components.

The GUI needs to be able to allow:

*** preload reading material from information read from a file such as ReadingMaterialInputFile.txt;

*** collect a customer's request for reading material in a particular category;
*** run a search to find all available reading material for a match;
*** print out the results of the search to the screen; and
*** calculate purchase price and write out the results to a file such as salesFile.txt.

Remember to incorporate as much error checking in your code to prevent problem user input.

Explanation / Answer

package com.online.shopping;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class CheckOut {
   public static void main(String[] args) throws IOException {
       ShoppingCart.loadDataFromFile();
       ShoppingCart cart = new ShoppingCart();
       int i;
       Scanner sc = new Scanner(System.in);
       List<Integer> booksList = new ArrayList<Integer>();
       do {
           System.out.println("Shopping Mall");
           System.out.println("=============");
           System.out.println("Select Menu(1-5)");
           System.out.println("1.Add Novel to shopping cart");
           System.out.println("2.Add TextBook to shopping cart");
           System.out.println("3.Add Magazine to shopping cart");
           System.out.println("4.Add Book to shopping cart");
           System.out.println("5.Exit");
           System.out.print("Enter option:");
           i = sc.nextInt();
           if (i <= 0 || i > 5) {
               System.out.println("Invalid Choice");
               System.out.println("Enter between 1 and 5");
               continue;
           }
           ReadingMatter type = null;
           if (i == 1) {
               booksList.clear();
               for (int j = 0; j < ShoppingCart.readingMatter.size(); j++) {
                   if (ShoppingCart.readingMatter.get(j) instanceof Novel) {
                       booksList.add(j + 1);
                       System.out.println(" ----------------------Novel id:"
                               + (j + 1));
                       System.out.println(ShoppingCart.readingMatter.get(j));
                       type = ShoppingCart.readingMatter.get(j);
                   }
               }
           } else if (i == 2) {
               booksList.clear();
               for (int j = 0; j < ShoppingCart.readingMatter.size(); j++) {
                   if (ShoppingCart.readingMatter.get(j) instanceof TextBook) {
                       booksList.add(j + 1);
                       System.out.println(" ----------------------Text Book id:"
                               + (j + 1));
                       System.out.println(ShoppingCart.readingMatter.get(j));
                       type = ShoppingCart.readingMatter.get(j);
                   }
               }
           } else if (i == 3) {
               booksList.clear();
               for (int j = 0; j < ShoppingCart.readingMatter.size(); j++) {
                   if (ShoppingCart.readingMatter.get(j) instanceof Magazine) {
                       booksList.add(j + 1);
                       System.out
                               .println(" ----------------------Magazine id:"
                                       + (j + 1));
                       System.out.println(ShoppingCart.readingMatter.get(j));
                       type = ShoppingCart.readingMatter.get(j);
                   }
               }
           } else if (i == 4) {
               booksList.clear();
               for (int j = 0; j < ShoppingCart.readingMatter.size(); j++) {
                   if (ShoppingCart.readingMatter.get(j) instanceof Book && !(ShoppingCart.readingMatter.get(j) instanceof Novel) && !(ShoppingCart.readingMatter.get(j) instanceof TextBook)) {
                       booksList.add(j + 1);
                       System.out.println(" ----------------------Book id:"
                               + (j + 1));
                       System.out.println(ShoppingCart.readingMatter.get(j));
                       type = ShoppingCart.readingMatter.get(j);
                   }
               }
           }
           if (i != 5) {
               System.out.print("Enter id to add the book to cart:");
               int k = 0;
               while (!booksList.contains((k = sc.nextInt()))) {
                   System.out.println("Invalid Option");
                   System.out.println("Please select from list:" + booksList);
               }
               if (cart.addToCart(k))
                   System.out
                           .println(" ===========Added to cart successfully================= ");
           }
           if(i==5)
           {
               int l=okcancel("You pay " + new DecimalFormat("#0.00").format(cart.getTotalPrice()));
               if(l!=0)//cancelled
                   i=1;
           }
       } while (i != 5);
       sc.close();
       System.out.println("You selected to exit");
       if(cart.cartBooks.size()>0){
       System.out.println("Cart contents:");
       System.out.println(cart.toString());
       System.out.println("You pay " + new DecimalFormat("#0.00").format(cart.getTotalPrice()));
       updateSales(cart);
       System.out.println("Payment success full");
       }
   }
   public static void updateSales(ShoppingCart cart) throws IOException {
       File file = new File("Sales.txt");
       if (!file.exists())
           file.createNewFile();
       ArrayList<String> sales = new ArrayList<String>();
       Scanner scan = new Scanner(file);
       int k=0;
       while (scan.hasNext()) {
           sales.add(scan.nextLine());
           k++;
           if(k==6)
               sales.clear();
       }
       scan.close();
       Date date = new Date();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
       String dateString = sdf.format(date);
       double bookPrice = 0, magPrice = 0, textPrice = 0, novelPrice = 0;
       System.out.println(sdf.format(date));
       for (int i = 1; i < sales.size(); i++) {
           if (i == 1) {
               bookPrice = Double
                       .parseDouble(sales.get(i).trim().split(":")[1]);
           }
           if (i == 2) {
               magPrice = Double
                       .parseDouble(sales.get(i).trim().split(":")[1]);
           }
           if (i == 3) {
               textPrice = Double
                       .parseDouble(sales.get(i).trim().split(":")[1]);
           }
           if (i == 4) {
               novelPrice = Double
                       .parseDouble(sales.get(i).trim().split(":")[1]);
           }
       }
       for (int i = 0; i < cart.cartBooks.size(); i++) {
           if (cart.cartBooks.get(i) instanceof Novel) {
               novelPrice+=cart.cartBooks.get(i).price;
           }
           else if (cart.cartBooks.get(i) instanceof Magazine) {
               magPrice+=cart.cartBooks.get(i).price;
           }
           else if (cart.cartBooks.get(i) instanceof TextBook) {
               textPrice+=cart.cartBooks.get(i).price;
           }
           else if (cart.cartBooks.get(i) instanceof Book) {
               bookPrice+=cart.cartBooks.get(i).price;
           }
       }
       FileWriter fw = new FileWriter(file,true);
       BufferedWriter bw = new BufferedWriter(fw);
       bw.write(dateString);
       bw.newLine();
       bw.write("BOOK:"+new DecimalFormat("#0.00").format(bookPrice));
       bw.newLine();
       bw.write("MAGAZINE:"+new DecimalFormat("#0.00").format(magPrice));
       bw.newLine();
       bw.write("TEXTBOOK:"+new DecimalFormat("#0.00").format(textPrice));
       bw.newLine();
       bw.write("NOVEL:"+new DecimalFormat("#0.00").format(novelPrice));
       bw.newLine();
       bw.newLine();
       bw.close();
   }
   public static int okcancel(String theMessage) {
   int result = JOptionPane.showConfirmDialog(null, theMessage,
   "alert", JOptionPane.OK_CANCEL_OPTION);
   return result;
   }
}

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