All pastes #673963 Raw Edit

Something

public java v1 · immutable
#673963 ·published 2007-08-28 20:38 UTC
rendered paste body
// File: Bike.javapublic class Bike{  // Represents a single bike  private int bikeNumber;  //  ID of bike  private String bikeType;  private float dailyRate; // Rate per day  private float deposit;   // Deposit  Bike(int bNo, String bType, float dayRate, float dep)  {    //Constructor that initialises by copying to stored values    bikeNumber = bNo;    bikeType = new String (bType);    dailyRate = dayRate;    deposit = dep;  }  public float getCharges(int numDays)  {    // Calculate cost of hire    return deposit + numDays * dailyRate;  }  public boolean findBike(int searchNo)  {    //Is this the bike sought?    return searchNo == bikeNumber;  }}// File: Hire.javapublic class Hire{  // Implements hiring of a given bike.  private Bike hiredBike;   // Link to bike hired  private int numDays;      // Hire details  private String startDate;   Hire(Bike aBike, int nDays, String stDate)  {    hiredBike = aBike;    numDays = nDays;    startDate = new String(stDate);  }  public void getDetails()   // Display hire details  {    System.out.println("Hiring began on "+ startDate + " for " + numDays +                       " days, at a cost of £" + hiredBike.getCharges(numDays));  }}// File: Customer.javapublic class Customer{  private String name;     // Customer's name  private Hire thisHire;   // Details of the hire  Customer(String custName)  {    name = new String(custName);    thisHire = null;  }  public boolean hireBike(Bike[] stock)  {    int searchNo;                   int hireDays;                   String start;                   boolean hiredOK = false;        int index=0;                    boolean found = false;          Bike chosenBike = null;         System.out.print("Enter Bike ID number>");	 searchNo = KBInput.readInt();    while (index<stock.length && !found)      {      found = (stock[index].findBike(searchNo));      if (found)        chosenBike = stock[index];              index++;    }    if (found)    {      System.out.print("How many days required");	       hireDays = KBInput.readInt();	   System.out.print("Start Date?");		      start = KBInput.readString();      thisHire = new Hire(chosenBike,hireDays,start);      hiredOK = true;    }    else      System.out.println("Bike Not found, Hire cannot be created");    return hiredOK;      }  public void showDetails()  // Display customer & hire details  {    System.out.println("Customer: "+ name );    if (thisHire != null)      thisHire.getDetails();    else      System.out.println("No hire details available");  }}