Question: Question 2 (25 points) Create the following classes. 1) Date with a) 3 private int fields: day, month, and hour. b) Public access getters for

Question 2 (25 points) Create the following classes. 1) Date with a) 3 private int fields: day, month, and hour. b) Public access getters for all fields: They return the int values. c) A single, public access constructor that takes the day, month, and year as parameters in that order. The constructor must validate all the three parameter values. i) Year must be 1500 or more. ii) Month must be between 1 and 12 (1 for January, 12 for December, etc.) iii) Day (should be 1 or more) and checked to be consistent with the value in month. Examples: If month is 4 (April), day must be 30 or less. If month is 2 (February), day must be 28 or less for non-leap years. For a leap year, if month is 2 (February), day should be 29 or less. A year is a leap year if it is divisible by 4. There is an exception though: If year is divisible by 100, it is a leap year if and only if it is divisible by 400. For examples: 2020 is a leap year because it is divisible by 4, but is not divisible by 100 1900 is not a leap year because it is divisible by 100, but not by 400. 2000 is a leap year because it is divisible by 400. 2021 is not a leap year because it is not divisible by 4 d) If one or more parameters values are incorrect, the Date constructor throws an Exception object with an appropriate String value (a message that indicates something is wrong with the parameters; it need not be very specific) passed to the Exception classs constructor. e) The class should not have any other fields or constructors or public or protected or package access methods. You may have private methods, if you wish. And no overriding methods. If you override any method or put any other fields or method or constructor, those cannot be used in the other classes. 2) Time with a) 2 private int fields: hour and minute. b) Public access getters for both fields: They return the int values. c) A public access constructor that takes the hour and minute as parameters in that order. The constructor must validate the two parameter values. i) Legal vales for hour are 0 through 23. ii) Legal vales for minute are 0 through 59. If either parameter is incorrect, the Time constructor throws an Exception object with an appropriate String value (a message that indicates something is wrong with the parameters; it need not be very specific) passed to the Exception classs constructor. d) The class should not have any other fields or constructors or public or protected or package access methods. You may have private methods, if you wish. And no overriding methods. If you override any method or put any other fields or method or constructor, those cannot be used in the other classes. 3) DateAndTime that uses a Date and Time object via composition appropriately. It should have a single, public constructor and a single public method named get(). You may have fields as appropriate for this problem. a) The constructor must have the following parameters in the given order: hour, minute, day, month, and year. b) The get() method should return a String object whose values must be consistent with the printout given below as output for the following code. DateAndTime dateAndTime = new DateAndTime(14, 55, 28, 2, 2021); System.out.println(dateAndTime.get()); 14:55 hours on 28 February 2021

Question 2 (25 points) Create the following classes. 1) Date with a)3 private int fields: day, month, and hour. b) Public access gettersfor all fields: They return the int values. c) A single, public

Question 1 (25 points) For the purposes of this problem, a Vehicle is a Java interface that can be one of many things, including a car or a Truck. Every Vehicle has the following three methods, with no implementation. The interface has no fields. public int getSeatingCapacity: public double getPrice(); public int getWarrantyPeriod(); First, code the Vehicle interface. Automobile satisfies the following requirements. 1) It implements Vehicle; 2) It is an abstract class; the class does NOT implement getWarrantyPeriod(). 3) It has two private attributes: price and seatingCapacity, with the usual semantics. 4) It has public getters for the two attributes to implement the first two methods listed for Vehicle, above. 5) It has exactly one protected constructor that takes the price and seating Capacity in that order as parameters and stores them appropriately in the fields. 6) It has a protected method named getMinimumWarrantyPeriod(), which returns 1. That is, every vehicle has a minimum warranty period of 1 year. This value might change in the future (by modifying the code in this method). 7) There are no setters. 8) You need not code/override any other methods. The class Car is a direct subclass of Automobile. You need to implement the Car class as specified in this problem. The class must implement functionality to compute the warranty period of a car as below. Every car has a warranty period that is one year more than the minimum warranty period (currently 1 year, but could change) for all vehicles. So, at present, every car will have at least two years of warranty, because the Vehicle class specifies it as 1 for all vehicles. Cars that are priced $30,000 or more have a warranty period of two years in addition to the warranty period for all vehicles, so right now, they will have 3 years of warranty. A Truck class represents a truck and is a direct subclass of Automobile. Every truck has a seating capacity of 2 and a warranty period that is 2 years more than the minimum warranty period given for all vehicles; so right now, they will have 3 years of warranty. You need to implement the Truck class as specified in this problem. No Car is a Truck and no Truck is a Car. Code the classes Vehicle, Truck, and Car to meet all the requirements described in this problem. The constructors and methods must conform to the following examples. It should be possible to a) change the Vehicle's minimum warranty period without manipulating the Car or Truck classes and b) change the Car's or Truck's warranty calculation without modifying the Vehicle minimum warranty period. Their warranty periods must change automatically as and when the minimum warranty period of a vehicle changes. Statements and Expressions Comment Value Returned (blank if no value) v1.getWarrantyPeriod() 2 The vehicle object has lyear minimum warranty. Since vi is priced less than $30,000, the extra warranty is 1 year and the total warranty is 2 car v2 = new Car (35000, 5); v2.getWarrantyPeriod() V2 is priced at $35,000 and can seat 5 3 The vehicle object has lyear minimum warranty. Since v2 is priced at $35,000, there is an additional period of 2 years of warranty. 5 Note that v2 was created to seat 5 35000.0 v2 is priced at $35,000 v2.getSeatingCapacity () V2.getPrice() Vehicle v3 = new Truck (80000); V3 is priced at $80,000 and can seat 2 passengers. v3.getWarrantyPeriod(); 3 The vehicle object has lyear minimum warranty. Being a truck, the warranty period is 3, right now. All trucks have a seating capacity of 2 13.getSeatingCapacity) 2 Question 1 (25 points) For the purposes of this problem, a Vehicle is a Java interface that can be one of many things, including a car or a Truck. Every Vehicle has the following three methods, with no implementation. The interface has no fields. public int getSeatingCapacity: public double getPrice(); public int getWarrantyPeriod(); First, code the Vehicle interface. Automobile satisfies the following requirements. 1) It implements Vehicle; 2) It is an abstract class; the class does NOT implement getWarrantyPeriod(). 3) It has two private attributes: price and seatingCapacity, with the usual semantics. 4) It has public getters for the two attributes to implement the first two methods listed for Vehicle, above. 5) It has exactly one protected constructor that takes the price and seating Capacity in that order as parameters and stores them appropriately in the fields. 6) It has a protected method named getMinimumWarrantyPeriod(), which returns 1. That is, every vehicle has a minimum warranty period of 1 year. This value might change in the future (by modifying the code in this method). 7) There are no setters. 8) You need not code/override any other methods. The class Car is a direct subclass of Automobile. You need to implement the Car class as specified in this problem. The class must implement functionality to compute the warranty period of a car as below. Every car has a warranty period that is one year more than the minimum warranty period (currently 1 year, but could change) for all vehicles. So, at present, every car will have at least two years of warranty, because the Vehicle class specifies it as 1 for all vehicles. Cars that are priced $30,000 or more have a warranty period of two years in addition to the warranty period for all vehicles, so right now, they will have 3 years of warranty. A Truck class represents a truck and is a direct subclass of Automobile. Every truck has a seating capacity of 2 and a warranty period that is 2 years more than the minimum warranty period given for all vehicles; so right now, they will have 3 years of warranty. You need to implement the Truck class as specified in this problem. No Car is a Truck and no Truck is a Car. Code the classes Vehicle, Truck, and Car to meet all the requirements described in this problem. The constructors and methods must conform to the following examples. It should be possible to a) change the Vehicle's minimum warranty period without manipulating the Car or Truck classes and b) change the Car's or Truck's warranty calculation without modifying the Vehicle minimum warranty period. Their warranty periods must change automatically as and when the minimum warranty period of a vehicle changes. Statements and Expressions Comment Value Returned (blank if no value) v1.getWarrantyPeriod() 2 The vehicle object has lyear minimum warranty. Since vi is priced less than $30,000, the extra warranty is 1 year and the total warranty is 2 car v2 = new Car (35000, 5); v2.getWarrantyPeriod() V2 is priced at $35,000 and can seat 5 3 The vehicle object has lyear minimum warranty. Since v2 is priced at $35,000, there is an additional period of 2 years of warranty. 5 Note that v2 was created to seat 5 35000.0 v2 is priced at $35,000 v2.getSeatingCapacity () V2.getPrice() Vehicle v3 = new Truck (80000); V3 is priced at $80,000 and can seat 2 passengers. v3.getWarrantyPeriod(); 3 The vehicle object has lyear minimum warranty. Being a truck, the warranty period is 3, right now. All trucks have a seating capacity of 2 13.getSeatingCapacity) 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!