Вы находитесь на странице: 1из 4

JAVA PROGRAMMING ASSIGNMENT

Problem Description
Write a program that simulates a simple online shopping system. The first thing you must do is to find a
partner to work with. Make sure you choose someone who will share the work equally with you.

Part 1: Application
(i) 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.

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 Magazines 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 Books 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.
(ii) 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: A Concise History of Australia
ISBN: 9780521601016
PRICE: 29.99
AUTHOR: Stuart Macintyre
MAGAZINE
TITLE: Time
ISBN: 9781933405162
PRICE: 4.95
EDITOR: Stengel, Richard
TEXTBOOK
TITLE: Java: How to Program
ISBN:9780131364837
PRICE: 123
AUTHOR: Deitel, Paul, Deitel, Harvey
ANSWERS: true
NOVEL
TITLE: Harry Potter and the Sorcerers Stone
ISBN: 059035342X
PRICE: 10.99
AUTHOR: Rowling, J. K.
CHARACTERS: Harry Potter, Ron Weasly, Hermione Granger
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.
(iii) 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.

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

Part 2: GUI application


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 assignment 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.

The appearance of the GUI is entirely up to you to decide. Remember to


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

Part 3: Server and client versions


For this part of the assignment you may assume that the ONLINE Shopping System running on the
server is preloaded with a group of reading material created using data from
ReadingMaterilaInputFile.txt. The client sends a UDP message (the customers request) to the

server, which is waiting to receive packets at a well-known IP address and UDP port number. (The
server's port number for this assignment is 13579.) The customer request contains the category and the
title of the reading material they wish to purchase.
The protocol for this problem runs on top of the Internet Protocol (IP) and the User Datagram Protocol,
UDP. Recall that a protocol is an agreement among communicating parties regarding the form and
meaning of the messages they send each other. It describes how messages are encoded, and how the
behaviour of each participant is affected by receiving each message, as well as when messages are sent.
You may be familiar with TCP, the protocol used for the Web and many other services. UDP provides a
best-effort message delivery service, instead of the reliable byte-stream service that TCP provides. UDP is
ideal for protocols that require only a single message in each direction, like the need for a customer to
communicate with the proposed OnLine Shopping System. Messages that stand alone, and are delivered
independently from other messages (with no guarantees about order or reliability) are called datagrams
(thus the name UDP).
The server, may or may, not implement the GUI. The server will validate the message received from a
customer, that is, checks that there is a student number and subject code in the message. The server runs
the customers request and then sends back a message with the title and isbn details of the first reading
material in its internal listing that is able to satisfy the customer request.
The client's initial message might be lost in the network. Therefore, if a response is
not received in a certain time (10 seconds), the client times out and retransmits the
request message; this may be repeated several times before the client finally gives
up and declares failure.

Вам также может понравиться