Questions:
1. Write a programme that computes the rental charge given the type of moped, when it is rented (weekday or weekend), and the number of hours rented.
The rental charges are as follows:
(a) Type of moped '50cc Mopette': Weekly rental is $15 for the ?rst 3 hours and $2:50 per hour after the ?rst 3 hours. Weekend rental is $30 for the ?rst 3 hours and $7:50 per hour after the ?rst 3 hours.
(b) Type of moped '250cc Mohawk': Weekly rental is $25 for the ?rst 3 hours and $3:50 per hour after the ?rst 3 hours. Weekend rental is $35 for the ?rst 3 hours and $8:50 per hour after the ?rst 3 hours.
Create a class called Moped with appropriate data members (attributes or properties) and methods. Be sure to have a constructor that can accept the size (50cc or 250cc) to determine the type of moped and another one for the different default rental amounts. The class design should include:
(a) Data Members (attributes): size, dayOfWeek, hours, name, three- HourPrice, hourlyPrice, totalCost.
(b) Constructors: Moped() (default values will be for 50cc) andMoped(int size, String day, int hours).
(c) Accessor (Get) Methods: getSize(), getDayOfWeek(), getHours(), getName(), getThreeHourPrice(), getHourlyPrice(), getTotalCost().
(d) Mutator (Set) Methods: setSize(int s), setDayOfWeek(String d), setHours(int h).
(e) Computation Methods: computeTotalCost, mopedName, isWeekend (you can also add some helper methods if you need).
The following UML diagram might be of assistance:
2. Write a driver class called MopedRental. This class should perform the following: asks the user to enter the size of the moped, the day of the week and the number of hours rented, creates the Moped object, based on the size, and displays the input data, type of moped and the total cost of the moped rental. Use the appropriate format for the output values.
3. Scoring in a single game of tennis starts with love-all, then scores of 15, 30, and 40. A player wins when he or she is two points ahead of their opponent and has a score of over 40, where the terms advantage server, deuce (tied score), and advantage receiver are used when the score is 40-all or higher.
Prepare a class called TennisGame that can be used to encapsulate the score in a single game of tennis. Then write a driver program called TennisSet, that plays a set of ?ve games of tennis between two players A and B (randomly choosing the winner of each point), ideally alternating the server for each game, and outputting a commentary of the progress and result of each game.