• This formative assessment consists of THREE Questions. (Answer ONLY TWO)
• The assessment is based on units 4 – 5 (Chapter 12 – 14 of the Java Programming Textbook).
• You can use either a console or Java Swing components (GUI) to answer your programming questions.
• Answer the questions outlined in the answer sheet and submit the completed sheet as a pdf.
• The code (programs) as described in the questions must be submitted as well.
• NOTE: SECTION A QUESTION 1 IS COMPULSORY.
SECTION B SELECT ONE QUESTION (QUESTION 2 OR QUESTION 3).
The assessment covers the following learning outcomes:
• Use recursion to solve mathematical problems
• Use the List interface
• Use the ArrayList class
• Use Swing components to capture and output information.
SECTION A (QUESTION 1 IS COMPULSORY)
Question 1 [25 marks]
Fun Times is a tourism company that provides adventurous itineraries around South Africa that are unique and engrossing. Fun Times co. specializes in group trips, with groups typically including 50 or more people. The company needs you to develop an application to capture trips and calculate their costs.
Use NetBeans IDE for all your programming questions. Create a class (Trip) to hold trip data for Fun Times. Your class header statement must be as follows:
Inside the class make sure you complete the following tasks:
1.1 Create four private variables that hold a trip number, number of guests for the trip, the price per guest, and the price for the trip. The trip number is stored as a String because the company plans to assign trip numbers such as T123. (4 marks)
1.2 Create two public setter methods that set/modify the trip number (setTripNumber()) and the number of guests (setGuests()). The setGuests() method will calculate the trip price by taking the number of guests multiplied by the price per guest every time the number of guests is set. The trip number MUST always be set as four digits (First a character followed by three numbers). If the input is otherwise the program must use a default trip number T000.
1.3 Create three public getter methods that return the values in the three non-static fields. getTripNumber(), getGuests(), and getPriceForTrip(). (5 marks)
1.4 Create a constructor that accepts a trip number and number of guests as parameters. Pass these values to the setTripNumber() and setGuests() methods, respectively. (5 marks)
The constructor calculates the price charged for the trip by multiplying the number of guests by the price per guest. The price per guest is R500 for small trips (50 guests or fewer) and R550 for large trips (more than 50 guests).
Use a default constructor provided for you below that passes T000 and 0 to the two-parameter constructor.
1.5 Create a toString() method that returns the trip number, number of guests, and total price in a readable format. (5 marks)
Use a compareTo() method provided for you below that overrides the Object class compareTo() method to compare trips based on their total price.