// LANDSCAPE GARDENING TYPE 1 QUOTE // Frans Coenen // University of Liverpool // 18 April 2013 import java.io.*; // PrintWriter class public class QuoteItemType1 extends QuoteItem { // ------------------- FIELDS ------------------------ /** The length of the type 1 landscape item. */ private double length = 0.0; /** The width of the type1 landscape item. */ private double width = 0.0; /** The area covered by the type 1 landscape item. */ private double area = 0.0; // ---------------- CONSTRUCTORS --------------------- /** Three argument constructor. @param name the name for this landscape gardening item. @@param unitMC the unit material cost (£s) for the type 1 landscape gardening item. @param unitIT the unit installation time (minutes)for the type 1 landscape gardening item. */ public QuoteItemType1(String name, double unitMC, double unitIT) { super(name,unitMC,unitIT); // Input length and width of landscape type 1 item System.out.print("Input length and width (doubles) of " + itemName + ": "); length = input.nextDouble(); width = input.nextDouble(); // Calculate costs calculateCosts(); } /** Five argument constructor. @param ln the length of the type 1 landscape gardening item. @param wd the width of the type 1 landscape gardening item. @param unitMC the unit material cost for the type 1 landscape gardening item. @param unitIT the unit installation time for the type 1 landscape gardening item. */ public QuoteItemType1(String name, double ln, double wd, double unitMC, double unitIT) { super(name,unitMC,unitIT); length = ln; width = wd; // Calculate costs calculateCosts(); } /** Method to calculate total installation time and total material cost for this type 1 landscape gardening item. */ private void calculateCosts() { // Calculate area area = length * width; // Calculate total installation time totalInstallationTime = area * unitInstallationTime; // Calculate total material cost totalMaterialCost = area * unitMaterialCost;} // ---------------- OUTPUT METHODS --------------------- /** To string method. */ public String toString() { String s = "Length and width of the " + itemName + " = " + length + " x " + width + "(m)\nTotal area of the " + itemName + " = " + area + " (m^2)\nUnit cost of the " + itemName + " = £" + unitMaterialCost + " (per m^2)\nTotal cost of the " + itemName + " = £" + Utility.twoDecPlaces(totalMaterialCost) + "\nTotal installation time = " + totalInstallationTime + "\n"; return(s); } /** Output to file @param fileOuput instance of PrintWriter calss. */ public void outputToFile(PrintWriter fileOutput) { fileOutput.println(length + "\n" + width + "\n" + unitMaterialCost + "\n" + unitInstallationTime); } }