Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1 a) ( 4 pts ) Create the following class Person class Person - name: String - hasDriverLicense: boolean - age: int //years - height:

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Q1 a) ( 4 pts ) Create the following class Person class Person - name: String - hasDriverLicense: boolean - age: int //years - height: int //inches + Person(String name, boolean hasDriverLicense, int age, int height) + getName(): String + hasDriverLicense(): boolean + getAge(): int + getHeight(): int + clone(): Person //returns a copy of the Person with all the same values without revealing the original memory address + equals(Object o) : boolean //2 Person objects are equal if all their variables are equal + toString(): String I/"Person[name=%10sage=%02d height =%02d has licenseo license]", name, age, height, hasDriverLicense Q1 b) ( 4 pts ) Create the following class InvalidDriverException class InvalidDriverException extends Exception + InvalidDriverException() + InvalidDriverException(String message) Q1 d) ( 1 pt ) Create the following interface Announcements interface Announcements + departure(): String //SEE NOTE 1 +arrival():String //SEE NOTE 2 + doNotDisturbTheDriver(): String //SEE NOTE 3 Notes for Interface Announcements: 1. The departure() method of a Car should return a line stating "All Aboardln", while a Bus should return a String containing 2 lines "All AboardlnThe Busin". The Bus implementation should make use of super.departure(). 2. The arrival() method of Car should return a line stating "Everyone Outln", while a Bus should return a String containing 2 lines "Everyone OuthnOf The Busin". The Bus implementation should make use of super.arrival(). 3. The doNotDisturbTheDriver() method of Car should return a line stating "No Backseat Drivingln", while a Bus should return a String containing 2 lines "No Backseat DrivinglnOn The Busln". The Bus implementation should make use of super.doNotDisturbTheDriver(). 5:29 . .11 Q1 e ) Create the following class Bus class Bus extends Car + Bus(int] numSeatsPerRow) -IISEE NOTE 1 + Bus(Person driver, int] numSeatsPerRow)-I/SEE NOTE 2 + canOpenDoor(Person p): boolean I/SEE NOTE 3 + canOpenWindow(Person p): boolean IISEE NOTE 4 + toString(): String I/SEE NOTE 5 Notes for Bus class: 1. This constructor calls the parent class's constructor, passing in 2 for the numDoors, numWindows equal to ( (2 * length of numSeatsPerRow array ) -1) since the first row only has 1 window, and as the last argument, numSeatsPerRow [ where the first row (index 0) always has 1 seat, while the rest of the array has numSeatsPerRow in each index. 2. This constructor does everything specified by (1) above, plus passes in the Person. 3. This method returns true if the Person is the driver, or seated in the last populated row. The Person must also be above the age of 5 , and taller than 40 inches. It returns false otherwise. 4. This method returns true if its parent class's canOpenWindow method returns true, and the Person is above the age of 5 . 5. This method prepends "Bus is an extension of " to the string returned from the Car class's to String () method before returning the entire string. 6. Be sure to implement the loadPassenger, and loadPassengers methods in the Bus class. Q1 e ) t to pen , Create the following class Bicycle class Bisycle extends Wohislo implements Cenperablexaicyelo? - weighti double + Bievelel NSEE NOTE 1 + Bicyceiperson diver) RSEE NOTE ? + Bicycleiperson diver, double weight) ISEE NOTE 3 + equals(Object o) boolan fisame weipht. ACCURACY, RANGE =0.5 ISEE NOTE 4 + getheighti) double + sefWoighticoublo w) weid + setDriver(Persea pl veid throas Invalis DriverExceptian MSEE NOTE 5 + toString: String NFicycle1 ridere " + gabriveri| gatNameil + * | weight" * + weight + * r + compare Toleigicycla b) MACCUPACY,RANGE =0.5 MSEE NOTE 6 Notes for Bisycle class: 1. This constructer cals the parent class 's construetor. pessing in 1 for the numRows ead 1 for the numseatuperRow belote intislizing woight to 0 . 2. This constructer cals the parent class's constructor, passing in the spected driver and an arry specifying that there is orly one row with ore seatbefore initialzing weight to 0 . 3. This constructer cals the parent class's eonstructer, passing in the spocifed driver and an array specitying that there is only one rew with ene seat belore serfing the weight (Neseve weight not permined. set to 0 if that oceurs). 4. Two bisycle ebisets are contidered equal if their weights are within 0.5 of each other regardless of who the driver is: 5. Override the inherited setDriver method so that any Persen age 3 or older can be the driver of the Bicycle. If the driver is yourges than 3, throw an Invalidoriverexception 6. If the calling object's weight is less than the passed in object's weight by more than the ACCURACY_RANCE retum -1 , if the celling object's weight is greater than the passed in ACCUPACY RANGE return 1, Odherwise retum 0. 7. Be sure to implement the losepassenger, and loadPassengers mathods in the Bicycle class. Hint A Bicycle cannot have any passengers. (A diver la not a passenger) loadPasengers mathods in the Bicyele class. driver is not a passenger? Q2) i 10 zt, Create a class named RecursionQuestion In this class you wil be using the Car class defined above, and you will be pertoming a binary tearch on an array of Car objects. Your class will have a method with the following cigrature. publle statle int binarysearchicarb ears, Car c) This mathod wil cal a recursive helper method to parlorm the binary search for the upecified Car e. In the exampins below, s to the start index, e is tee end index, and mid is the mid holex at each phase of the tectersice meriod cells. When the ear being searched for is found, your cede wit. produce oupet simiar to the following Looking foz Cats numbef of deet =02 i n=0,0=7, mides ge inte of tighe go x thet robus at 3 When the car being seanched for is not found, your code will prectuce eutput simile is the folowirg tooking -for Cary number of decre * of I =0, e=3, nid =4 go teft ge tets Mot Found Please note that the line beginning wor, teoking fat cart is actualy Looking far Car * * etoString0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

Explain the link between positive thinking and good health.

Answered: 1 week ago

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago