Untitled
unknown
plain_text
23 days ago
5.1 kB
2
Indexable
Never
/* Class Diagram Machine +-------------------+ | - brand: str | | - typeName: str | | - manufactureYear: int| | - shade: str | |-------------------| | + showSpecs() | | + powerOn() | +-------------------+ | v +-------------------+ | Coupe | | - doorNumber: int | |-------------------| | + showSpecs() | | + powerOn() | +-------------------+ | v +-------------------+ | Lorry | | - maxLoad: double | | - trayLength: double| |-------------------| | + showSpecs() | | + powerOn() | +-------------------+ | v +-------------------+ | Moped | | - cylinderVolume: int| |-------------------| | + showSpecs() | | + powerOn() | +-------------------+ | v +-------------------+ | OxCart | | - cartCapacity: int| |-------------------| | + showSpecs() | | + powerOn() | +-------------------+ */ class Machine { private String brand; private String typeName; private int manufactureYear; private String shade; // Constructor for Machine public Machine(String brand, String typeName, int manufactureYear, String shade) { this.brand = brand; this.typeName = typeName; this.manufactureYear = manufactureYear; this.shade = shade; } // Display details of the machine public void showSpecs() { System.out.println("Brand: " + brand); System.out.println("Type Name: " + typeName); System.out.println("Manufacture Year: " + manufactureYear); System.out.println("Shade: " + shade); } // Start the machine public void powerOn() { System.out.println("Powering on the machine..."); } } class Coupe extends Machine { private int doorNumber; // Constructor for Coupe public Coupe(String brand, String typeName, int manufactureYear, String shade, int doorNumber) { super(brand, typeName, manufactureYear, shade); this.doorNumber = doorNumber; } // Display details of the coupe @Override public void showSpecs() { super.showSpecs(); System.out.println("Number of Doors: " + doorNumber); } // Start the coupe engine @Override public void powerOn() { System.out.println("Powering on the coupe..."); } } class Lorry extends Machine { private double maxLoad; private double trayLength; // Constructor for Lorry public Lorry(String brand, String typeName, int manufactureYear, String shade, double maxLoad, double trayLength) { super(brand, typeName, manufactureYear, shade); this.maxLoad = maxLoad; this.trayLength = trayLength; } // Display details of the lorry @Override public void showSpecs() { super.showSpecs(); System.out.println("Maximum Load: " + maxLoad + " tons, Tray Length: " + trayLength + " meters"); } // Start the lorry engine @Override public void powerOn() { System.out.println("Powering on the lorry..."); } } class Moped extends Machine { private int cylinderVolume; // Constructor for Moped public Moped(String brand, String typeName, int manufactureYear, String shade, int cylinderVolume) { super(brand, typeName, manufactureYear, shade); this.cylinderVolume = cylinderVolume; } // Display details of the moped @Override public void showSpecs() { super.showSpecs(); System.out.println("Cylinder Volume: " + cylinderVolume + " cc"); } // Start the moped engine @Override public void powerOn() { System.out.println("Powering on the moped..."); } } class OxCart extends Machine { private int cartCapacity; // Constructor for OxCart public OxCart(String brand, String typeName, int manufactureYear, String shade, int cartCapacity) { super(brand, typeName, manufactureYear, shade); this.cartCapacity = cartCapacity; } // Display details of the ox cart @Override public void showSpecs() { super.showSpecs(); System.out.println("Cart Capacity: " + cartCapacity + " cubic meters"); } // Start the ox cart (metaphorically) @Override public void powerOn() { System.out.println("Powering on the ox cart..."); } } public class Main { public static void main(String[] args) { // Create instances of each class Coupe coupe = new Coupe("Tesla", "Model S", 2022, "Midnight Silver", 2); Lorry lorry = new Lorry("Volvo", "FH16", 2021, "Dark Blue", 20.0, 8.0); Moped moped = new Moped("Honda", "Zoomer", 2023, "Yellow", 50); OxCart oxCart = new OxCart("Farmer's Choice", "Traditional", 2024, "Wooden", 3); // Display details and ignite engines coupe.showSpecs(); coupe.powerOn(); lorry.showSpecs(); lorry.powerOn(); moped.showSpecs(); moped.powerOn(); oxCart.showSpecs(); oxCart.powerOn(); } }
Leave a Comment