// LANDSCAPE GARDENING TYPE 2 QUOTE // Frans Coenen // University of Liverpool // 18 April 2013 import java.util.*; import java.io.*; // PrintWriter class public class QuoteItemType2 extends QuoteItem { // ------------------- FIELDS ------------------------ /** The quantity of the type 2 landscape items. */ private int quantity = 0; // ---------------- CONSTRUCTORS --------------------- /** Three argument constructor. @param name the name for this 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 QuoteItemType2(String name, double unitMC, double unitIT) { super(name,unitMC,unitIT); // Input length and width of landscape type 1 item System.out.print("Input quantity (int) of " + itemName + "(s) : "); quantity = input.nextInt(); // Calculate costs calculateCosts(); } /** Four argument constructor. @param qu the quantity of the type 2 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 QuoteItemType2(String name, int qu, double unitMC, double unitIT) { super(name,unitMC,unitIT); quantity = qu; // Calculate costs calculateCosts(); } /** Method to calculate total installation time and total material cost for this type 1 landscape gardening item. */ private void calculateCosts() { // Calculate total installation time totalInstallationTime = quantity * unitInstallationTime; // Calculate total material cost totalMaterialCost = quantity * unitMaterialCost; } // ---------------- OUTPUT METHODS --------------------- /** To string method. */ public String toString() { String s = "Quantity of " + itemName + "(s) = " + quantity + "\nUnit Cost of the " + itemName + " = £" + unitMaterialCost + "\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(quantity + "\n" + unitMaterialCost + "\n" + unitInstallationTime); } }