Question
TestBoat.java coding here: import java.util.*; /** * TestBoat ... a class to test the Boat and Motor class hierarchies */ public class TestBoat { //
TestBoat.java coding here:
import java.util.*;
/** * TestBoat ... a class to test the Boat and Motor class hierarchies */
public class TestBoat { // Main program public static void main(String[] args) { // check for two boats worth of info in args if(args.length != 6) { System.out.println("There should be 3 arguments per boat: " + " HullID, Model, Type " + "and there should be 2 boats (= 6 arguments)"); System.exit(1); } // Get boat 1 info String hullid = args[0]; String model = args[1]; String type = args[2]; // Make an Outboard motor, store it as a Motor, and pass to Boat constructor Motor motor1 = new Outboard("Mercury", 2005, 90, "4-stroke"); Boat boat1 = new Boat(hullid, model, type, motor1); System.out.println("boat1: " + boat1 + " "); // Get boat 2 info hullid = args[3]; model = args[4]; type = args[5]; // Make an InboardOutboard motor, store it as a Motor, and pass to Boat constructor Motor motor2 = new InboardOutboard("OMC", 1989, 170, 6); Boat boat2 = new Boat(hullid, model, type, motor2); System.out.println("boat2: " + boat2); } }
In this example, we are going to model boats in a boat dealer's inventory. Here is the UML for this example Boat mfg (String) //manufacturer code) -serialNumber (int) month (nt)//of mfg modelYear (int) modelName (String) type (String) motor (Motor) +Boat(_hullid.-model, Motor make (String) year (int) hp (int) +Motor)//constructor +Motor make,_year, _hp) type, _motor) //constructor +ge tHullD0:String //constructor toString():String +toString):String Outboard InboardOutboard type (String) cylinders (int) +Inboardoutboard( //2-stroke or 4-stroke +Outboard_make, _year, _hp, _type) make,_year, _hp, cylinders) //constructor //constructor +toString):String +toString):String NOTES: Outboard is-a Motor... InboardOutboard is-a Motor... Boat has-a Motor Implement these four classes, plus a test class. The test class will instantiate two boats and two Motors (one for each) and then print out the toString() for each boat. In this example, we are going to model boats in a boat dealer's inventory. Here is the UML for this example Boat mfg (String) //manufacturer code) -serialNumber (int) month (nt)//of mfg modelYear (int) modelName (String) type (String) motor (Motor) +Boat(_hullid.-model, Motor make (String) year (int) hp (int) +Motor)//constructor +Motor make,_year, _hp) type, _motor) //constructor +ge tHullD0:String //constructor toString():String +toString):String Outboard InboardOutboard type (String) cylinders (int) +Inboardoutboard( //2-stroke or 4-stroke +Outboard_make, _year, _hp, _type) make,_year, _hp, cylinders) //constructor //constructor +toString):String +toString):String NOTES: Outboard is-a Motor... InboardOutboard is-a Motor... Boat has-a Motor Implement these four classes, plus a test class. The test class will instantiate two boats and two Motors (one for each) and then print out the toString() for each boatStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started