关于算法:COSC1073-RMIT-Classification

53次阅读

共计 15823 个字符,预计需要花费 40 分钟才能阅读完成。

RMIT Classification: Trusted
COSC1073 Programming 1, Semester 1 2022
Background Information
For this assessment you need to write an object-oriented console application in the Java programming
language which adheres to the following basic object-oriented programming principles:
a) Your code should follow good object-oriented principles such as encapsulation, composition,
cohesion, etc…
b) Setting the visibility of all instance variables to private or protected.
c) Using getter and setter methods only where needed and appropriate with consideration given
to scope & visibility.
d) Only use static variables and methods when there is good reason to do so, such as reducing
code repetition whilst still maintaining good objected-oriented design.
e) Using superclass methods to retrieve and / or manipulate superclass properties from within
subclasses, avoiding direct access to class attributes if possible.
You are being assessed on your ability to write a program in an object-oriented manner. Writing the
program in a procedural style is not permitted and will be considered inadmissible receiving a zero
grade.
Programming guidelines
The following guidelines apply throughout this assessment:
f) Arrays should be appropriately sized.
g) You must use an array to store any collections of objects in your program.
h) You must not use ArrayList, HashMap or any other data structures within the Java API or from
3rd party libraries.
i) You are not permitted to use streams from Java 1.8.
j) You must use the provided program template, and must not modify the main() method.
Page 1 of 11
Page 2 of 11
RMIT Classification: Trusted
Overview
The manager of a theatre wants you to build an online program that allows customers to buy tickets
online. The system will be able to:
? Create a sale or a cart. ? Add tickets to the cart. ? Display the details of the cart.
? Updating the cart.
? Check-out.
You will be addressing these requirements by implementing a series of classes designed to meet these
needs. The classes must be designed according to object-oriented principles.
Getting Started
This assessment is divided up into several stages:
? Stage 1 – A ticket to be added (6 marks)
? Stage 2 – A cart to hold the ticket(s) (9 marks) ? Stage 3 – Updating the ticket(s) in the cart (9 marks)
? Stage 4 – VIP features (10 marks)
? Code quality (6 marks)
The assessment is designed to be easy at earlier stages but more difficult in later stages. The
specification will be more descriptive in the earlier stages. The later stages of the assessment are less
descriptive as you will need to be more independent and resolve design issues on your own.
RMIT Classification: Trusted
Stage 1 – A ticket to book
In this stage, you will implement a basic online shopping cart. You are required to create one class:
Ticket.
Build the Ticket class with the following specifications:
? Instance variables
o String name
o int price
o int quantity
? No-argument constructor Ticket()
o Initialize name to String“UNKNOWN”o Initialize price to -1 o Initialize quantity to 0
? Constructor ticket(String name, int price, int quantity) o Initialize instance variable name to name if the latter is not null
o Initialize instance variable price to price if the latter is >= 0
o Initialize instance variable quantity to quantity if the latter is >= 1
o If any of the parameter passed in is invalid, throw IllegalArgumentException.
? Public mutators & accessors
o setName(String name) & getName()
o setPrice(int price) & getPrice()
o setQuantity(int quantity) & getQuantity()
o Setters should consider the validity of the parameter passed in
? Public method getTotalPrice() which returns the total cost of the item to purchase. The total
price is computed using the formula: price * quantity
? Override the toString() method which returns the following String:
o“name quantity X $price = $totalCost”
The CartManager class contains the main() method. Complete the stage1(Ticket ticket) method,
which prompts the user for one ticket and sets the attributes of Ticket passed into stage1(). Print the
information of the item. Example outputs are as follows. Given the same user input, your program is
expected to produce the same output as follows. Only minor format differences (e..g., extra line break)
are allowed.
Stage 1
Enter the name of the ticket:
The Matrix Reloaded
Enter the ticket price:
15
Enter the quantity:
3
The Matrix Reloaded 3 X $15 = $45
Page 3 of 11
Page 4 of 11
RMIT Classification: Trusted
Stage 2 – A basic shopping cart
You must complete Stage 1 before attempting Stage 2. If Stage 1 has not been completed Stage 2 will
not be assessed.
In this stage, you will create a basic shopping cart. The shopping cart is supposed to (1) store a
customer’s information; (2) allow a customer to add items; and (3) compute the total cost of the items
within the shopping cart.
Implement the class ShoppingCart. Specifically, the ShoppingCart class should contain:
? Private fields
o String customerName
o String date
o Ticket[] inCartTickets o static final int CAPACITY of value 5 (provided)
o int count
? No-argument constructor ShoppingCart()
o Initialize customerName to String“UNKNOWN”o Initialize date to String“1 May 2022”o Initialize cartTickets to an empty array of size CAPACITY
o Initialize count to 0
? Constructor ShoppingCart(String name, String date) o Initialize instance variable name to name
o Initialize instance variable date to date
o Initialize inCartTickets to an empty array of size CAPACITY
o Initialize count to 0
? Public accessor getName() which returns the customer name of the shopping cart
? Public mutator setName(String name) which sets the customer name
? Public accessor getDate() which returns the sign up date of the customer
? Public mutator setDate(String date) which sets the current date of shopping cart
? Public member method add(Ticket ticket), which adds the ticket parameter to inCartTickets
array. The method determines whether the ticket passed in is not null and is different to any
ticket in inCartTickets. If yes, it adds ticket to the shopping cart and returns true. Otherwise,
it prints a message“Ticket invalid or already added.”and returnsfalse. Note, all tickets should
have different names ignoring cases.“Star wars”,“star wars”and“Star Wars”are considered
the same. If the shopping cart is full, the ticket then cannot be added. It prints“SHOPPING
CART IS FULL”and returns false.
? Public member method getCount() which returns quantity of all tickets in cart. Note that the
quantity of all tickets must be computed as the total quantity of all different ticketsin the cart.
E.g. if there are 1 sale of 3 tickets and 1 sale of 1 ticket, the method will return 4, not 2. ? Public member method getCost() which returns the total cost of the tickets in cart.
? Public member method printTotal() which outputs (1) the customer and the date; (2) number
of total sales in the shopping cart; (3) the information of each sale in the shopping cart; and
(4) the total cost of the shopping cart. If the cart is empty, outputs (1) the customer and the
Page 5 of 11
RMIT Classification: Trusted
date; and (2) the message“SHOPPING CART IS EMPTY.”. Please refer to the example outputs
when implementing this method.
Complete stage2(ShoppingCart cart) method in CartManager. Ask user to enter name and date. Sets
the customerName and date of cart passed in. Print the information of the shopping cart created by
calling printTotal() (note, it is the first-time calling printTotal() ).
Prompt the user for two ticket sales, create two objects of the Ticket class, and add these two objects
into the shopping cart created. Hint: Before prompting for the second item, you may need to call
scanner.nextLine(); to allow the user to input a new string (depends on your program). Print info of
the shopping cart by calling printTotal() (calling printTotal() for the second time).
Example outputs are as follows. Given the same user input, your program is expected to produce the
same output . Only minor format differences (e..g., extra line break) are allowed.
Example output after printTotal() is called for the first time:
Stage 2
Enter the name of the customer:
Andrew Smith
Enter the current date:
1 May 2022
Andrew Smith – 1 May 2022
SHOPPING CART IS EMPTY
Example outputs after printTotal() is called for the second time:
Enter the name of the ticket:
The Matrix Reloaded
Enter the ticket price:
15
Enter the quantity:
3
Enter the name of the ticket:
Top Gun
Enter the ticket price:
25
Enter the quantity:
2
Andrew Smith – 1 May 2022
Number of tickets: 5
The Matrix Reloaded 3 X $15 = $45
Top Gun 2 X $25 = $50
Total cost: $95
User Prompt in stage2()
Example output of the first printTotal() call
Example output of the second printTotal() call
RMIT Classification: Trusted
Stage 3 – Updating the shopping cart
You must complete Stage 2 before attempting Stage 3. If Stage 2 has not been completed Stage 3 will
not be assessed.
In this stage, you will need to allow user to update the items already added to the shopping cart. You
need to extend the ShoppingCart class by adding:
? Public method removeTicket(String ticketName) o It removes a ticket from the shopping cart if its name matches with the parameter
ticketName. After removing, output this message“Ticket ticketName removed from
the cart”. It returns true in this case. o If no item in the cart matches with ticketName, print this message“Ticket not found.
Cart remains unchanged.”It returns false in this case.
? Public method updateTicket(String ticketName)
o Modifies a ticket’s quantity and returns true if successful. o If an item with a matched name of the parameter ticketName can be found in cart,
prompt the user to enter the new quantity with the message“Please enter the new
quantity:”. Update the ticket quantity according to the user input. o If the ticket cannot be found (by ticketName), print the message:“Ticket not found.
Cart remains unchanged.”and return false.
? Public method checkout()
o Generate a summary of the shopping cart by calling printTotal(). Allow customer to
check-out.
o Removes all items from the shopping cart and returns true. o If the shopping cart is empty, do not generate a summary. Instead, output the
message“SHOPPING CART IS EMPTY.”and returns false.
Implement stage3() method in CartManager. Note that in main(),stage3() will work on the cart object
that has been updated by Stage 2. Ask user for the ticket to be removed. Perform the removal by
calling removeTicket(String ticketName), and print the summary of the cart by calling the printTotal().
Next, ask for the ticket name to be modified, then call updateTicket(String ticketName). Print the
information of the shopping cart by calling the printTotal() method. Finally, prompt the user to check?out and call the checkout() method.
Example outputs are as follows. Given the same user input, your program is expected to produce the
same output as follows. Only minor format differences (e..g., extra line break) are allowed.
Stage 3
Do you want to remove a ticket from the cart? Y/N
Y
Enter the name of the ticket:
Case insensitive
top gun
Top Gun removed from the shopping cart.
Andrew Smith – 1 May 2022
Number of tickets: 3
The Matrix Reloaded 3 X $15 = $45
Total cost: $45
Page 6 of 11
Page 7 of 11
RMIT Classification: Trusted
Another example:
Stage 3
Do you want to remove a ticket from the cart? Y/N
Y
Enter the name of the ticket:
Topgun
Ticket not found. Cart remains unchanged.
Andrew Smith – 1 May 2022
Number of tickets: 5
The Matrix Reloaded 3 X $15 = $45
Top Gun 2 X $25 = $50
Total cost: $95
Example outputs of updateTicket() and printTotal(). Assume 2 tickets of“Top Gun”in the cart.
Do you want to update a ticket from the cart? Y/N
Y
Enter the name of the ticket:
Top gun
Please enter the new quantity:
4
Andrew Smith – 1 May 2022
Number of tickets: 7
The Matrix Reloaded 3 X $15 = $45
Top Gun 4 X $25 = $100
Total cost: $145
Example outputs after calling checkout() if not empty.
Do you want to checkout? Y/N
Y
Andrew Smith – 1 May 2022
Number of tickets: 7
The Matrix Reloaded 3 X $15 = $45
Top Gun 4 X $25 = $100
Total cost: $145
Thank you for shopping
No such ticket!
Case insensitive.
Page 8 of 11
RMIT Classification: Trusted
Stage 4 – VIP Shopping Cart
You must complete Stage 3 before attempting Stage 4. If Stage 3 has not been completed Stage 4 will
not be assessed.
In this stage, you will extend the program to create a shopping cart for VIP customer. VIP customers
have a few privileges:
(1) If the total price of purchased ticket is greater or equal to $100, then the last ticket is free for one.
Using the last example from Stage 3, Andrew Smith ordered 4 tickets for Top Gun but only needs to
pay for 3, e.g. $75.
(2) Collect points after check-out. The number of points collected is equal to the cost that a customer
actually pays at check-out. If a VIP pays $75 at check-out, then 75 points will be rewarded.
(3) A VIP customer can use the points to pay at check-out. Specifically, every 20 points can be used
equivalently as $1. When a VIP proceeds to check-out, your program should prompt the user for
number of points he/she wishes to use. When using points to pay, a customer can only use multiples
of 20 points, e.g., 20, 40, 100 points etc. If the customer enters a number that is not multiples of 50,
the nearest lower multiple of 20 will be used, e.g. 80 for 95, 40 for 49. If the customer enters a number
greater than the total points available, print the message:“Not enough points. Please re-enter or enter
-1 to quit point redeeming.”. If a valid number is entered, deduct the points from balance and continue
the checkout. If -1 is entered, the program will proceed with the normal checkout.
To achieve the above requirements, you will need to implement a new class VIPCart that is a subclass
of the ShoppingCart class. Additional private fields, new methods or overridden methods may be
added. You then need to implement stage4() method. In this method, prompt the user to create a
VIP shopping cart. Add one item to the shopping cart, and then call checkout().
Example outputs are as follows. Given the same user input, your program is expected to produce the
same output as follows. Only minor format differences (e..g., an extra line break) are allowed.
Example, a VIP ordered 3 tickets of“The Matrix Reloaded”, and redeemed 100 points at checkout.
Stage 4
Enter the name of the VIP customer:
Andrew Smith
Enter the current date:
1 May 2022
Enter the VIP points available:
350
Enter the name of the ticket:
The Matrix Reloaded
Enter the ticket price:
15
Enter the quantity:
3
Andrew is a VIP!
Page 9 of 11
RMIT Classification: Trusted
Andrew Smith – 1 May 2022
Number of tickets: 3
The Matrix Reloaded 3 X $15 = $45
Total cost: $45
Do you want to checkout? Y/N
Y
How many points to redeem? Enter -1 to checkout without using points.
118
Redeemed 100 points for $5
Total price paid: $40
40 VIP pointed added. Available 290 points.
Thank you for shopping
Andrew from the above example is now buying two sets of tickets. Assume he has 350 VIP points.
Enter the name of the ticket:
The Matrix Reloaded
Enter the ticket price:
15
Enter the quantity:
3
Enter the name of the ticket:
Top Gun
Enter the ticket price:
25
Enter the quantity:
4
Andrew Smith – 1 May 2022
Number of tickets: 7
The Matrix Reloaded 3 X $15 = $45
Top Gun 4 X $25 = $75 (with VIP discount)
Total cost: $120
Do you want to checkout? Y/N
Y
How many points to redeem? Enter -1 to checkout without using points.
-1
100 points redeemed, not 118 points!
The last ticket is free!! So only pay for 3.
Page 10 of 11
RMIT Classification: Trusted
No VIP points used
Total price paid: $120
120 VIP pointed added. Available 470 points.
Thank you for shopping
Marking Guide
Implementation of Ticket class
? Private fields, mutators, and accessors
? Constructors
? Mutators & accessors
? getTotalPrice()
? toString()
Implementation of stage1()
[5 marks] [1 mark] [1 mark] [1 mark] [1 mark] [1 mark]
[1 mark]
Implementation of ShoppingCart class
? Private fields, mutators and accessors
? Constructors
? add()
? geCount()
? getCost()
? printTotal()
[8 marks]
[1 mark] [1 mark] [2 marks]
[1 mark] [1 mark] [2 marks]
Implementation of stage2() [1 mark]
Extending ShoppingCart class
? removeTicket()
? updateTicket()
? checkout()
Implementation of stage3()
[7 marks] [3 marks]
[3 marks]
[1 mark]
[2 marks]
Implementation of VIPCart class
? VIP points accumulation
? Redeeming VIP points
? VIP discount for order over $100
[8 marks]
[2 marks]
[3 marks]
[3 marks]
Implementation of stage4() [2 marks]
Code quality
? No duplicate codes (segments with overlap of >= 3 lines)
? Proper variable names
? Comments
? Consistent indentation
? No overly long methods (methods >= 50 lines)
? No magic numbers
[6 marks]
[1 mark] [1 mark] [1 mark] [1 mark] [1 mark] [1 mark]
Total [40 marks]
Penalties

  • Late penalty: 10% per day up to 5 days (100% after that)
    • 120
      Page 11 of 11
      RMIT Classification: Trusted
  • Code cannot be compiled (or not executable): 100% penalty
  • Code is not following OOP principles (being procedural), Java8 and other
    programming guidelines: up to 100% penalty
  • Code crashes during a‘normal’run: up to 50% penalty
    Submission Instructions
    Submit on Canvas as a zip file
    Export the project as an archive; the file name should be the same as the project name, for example
    s1234567_Assessment2.zip and submit the zip file to Canvas under Assignments.
    To export a project as a zip file in IntelliJ, click File -> Export -> Project to zip file.
    Academic Integrity and Plagiarism (Standard RMIT Warning)
    Your code will be automatically checked for similarity against other submissions so please make sure
    your submitted project is entirely your own work.
    Academic integrity is about honest presentation of your academic work. It means acknowledging the
    work of others while developing your own insights, knowledge, and ideas. You should take extreme
    care that you have:
    ? Acknowledged words, data, diagrams, models, frameworks and / or ideas of others you have
    quoted (i.e., directly copied), summarised, paraphrased, discussed, or mentioned in your
    assessment through the appropriate referencing methods.
    ? Provided a reference list of the publication details so your reader can locate the source if
    necessary. This includes material taken from internet sites.
    If you do not acknowledge the sources of your material, you may be accused of plagiarism because
    you have passed off the work and ideas of another person without appropriate referencing, as if they
    were your own.
    RMIT University treats plagiarism as a very serious offence constituting misconduct. Plagiarism covers
    a variety of inappropriate behaviours, including:
    ? Failure to properly document a source.
    ? Copyright material from the internet or databases.
    ? Collusion between students.
    For further information on our policies and procedures, please refer to the University website.
    Assessment Declaration
    When you submit your project electronically, you agree to the RMIT Assessment Declaration.
正文完
 0