Question: Lab 1 0 ( from Ch 1 0 ) Interfaces 1 . Using interfaces, you can specify similar behaviors for possibly disparate classes. Governments and
Lab from Ch
Interfaces
Using interfaces, you can specify similar behaviors for possibly disparate classes. Governments and companies worldwide are becoming increasingly concerned with carbon footprints annual releases of carbon dioxide into the atmosphere from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. Create three small classes unrelated by inheritanceclasses Building, Car, and Bicycle. Write an interface CarbonFootprint with a getCarbonFootprint method. Have each of your classes implement that interface so that its getCarbonFootprint method prints out an appropriate message eg this message from Building CarbonFoot Write an application that creates objects of each of the three classes and one interface reference variable, assign each object to the interface reference variable, and then invoke each objects getCarbonFootprint method by means of dynamic method dispatch. For each object, print a simple message eg this message from Building CarbonFoot
Submit: CarbonFootprint.java, Building.java, Car.java, Bicycle.java, CarbonFootprintDemo.java
Write Yacht, CruiseShip, and CargoShip classes that implement a describable interface, which defines a describeShip method
A Yacht class has the following members
A field for the name of the yacht a string
A field for the year that the yacht was built a string
A field for the owner of the yacht a string
A constructor and appropriate accessors and mutators.
A describeShip method that describes the name, year and owner of a yacht.
A CruiseShip class has the following members:
A field for the name of the CruiseShip a string
A field for the cities that the CruiseShip visits an array of string
A field for the maximum number of passengers an int
A constructor and appropriate accessors and mutators.
A describeShip method that describes the name, cities, maximum number of passengers of a cruise ship.
A CargoShip class has the following members:
A field for the name of the CargoShip a string
A field for the capacity in tonnage an int
A field for the port of departure a string
A field for the port of destination a string
A constructor and appropriate accessors and mutators.
A describeShip method that describes the name, capacity, the ports of departure and destination.
Demonstrate the classes in a program ShipTest that has a describable interface array. Assign various Yacht, CruiseShip, and CargoShip objects to the array elements. The program should then step through the array, calling each objects describeShip method.
Submit: Yacht.java, CruiseShip.java, CargoShip.java, Describable.java, ShipTest.java
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
