Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class CourseListException that extends Exception with the following cons

ID: 652112 • Letter: W

Question

Write a class CourseListException that extends Exception with the following constructors:

A default constructor that gives the error message "Too many courses."

A constructor that takes a string and uses this for the error message

Part II

Write a class Boat with the following attributes:

Two instance variables (with corresponding getters and setters):

name - a String for the name of the boat

passengers - an array of Strings with length 5, holding the names of the passengers being transported.

A default constructor that initializes name to be "NoName".

A constructor that takes a String to set the name of the boat

Two methods:

assignPassengers (no input parameters or return values) - This method should ask a user to input passengers from the console window until the user enters an empty line, which indicates the end of the array. If the user enters more than 5 Passengers, throw a PassengerListException

writeBoat (no input parameters or return values) - writes the name of the boat and the names of the boats's passengers to the console window

Part III

Write a class Canoe, a subclass of Boat, for a boat which can take at most 2 passengers. The class should include the following:

A default constructor that invokes the superclass constructor

A constructor that takes a String to set the name of the Canoe

An overridden assignPassengers that throws a PassengerListException when a user tries to assign more than 2 passengers to a Canoe.

Part IV

Write a class TestBoat that does the following:

Creates a boat with the name Titanic

Assigns some passengers to Titanic

Writes the information about Titanic to the console window

Creates a Canoe with the name C2

Assigns courses to C2

Writes the information about C2 to the console

Explanation / Answer

class CourseListException extends Exception

{

CourseListException()

{

System.out.println("Too many courses");

}

CourseListException(String s)

{

System.out.println("you have error as "+s);

}

};

Part II

class Boat

{

int a1,b1;

String name;

String [] passengers = new String[5];

Boat()

{

name="NoName";

}

Boat(String s)

{

name=s;

}

void assignPassengers()

{

String ss;

DataInputStream o = new DataInputStream(System.in);

while(1)

{

System.out.println("Enter passenger");

ss=o.readLine();

if(ss==null)

{

break;

}

else

{

if(i<5)

{

s[i]=ss;

}

else

{

System.out.println("Passengers Full");

break;

}

}

}

};

Part III

class Canoe extends Boat

{

String name;

super Canoe()

{

}

Canoe(String s)

{

name =s;

}

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote