Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to modify the worked-example of ABC Wash Machine and print out the above statistical information. public class Clock { private int hr;

Your task is to modify the worked-example of ABC Wash Machine and print out the above statistical information. 

public class Clock

{

 private int hr; //store hours

 private int min; //store minutes

 private int sec; //store seconds


//Constructor with parameters, to set the time

//The time is set according to the parameters

//Postcondition: hr = hours; min = minutes; sec = seconds

 public Clock(int hours, int minutes, int seconds)

 {

   setTime(hours, minutes, seconds);

 }


//Default constructor

//Postcondition: hr = 0; min = 0; sec = 0

 public Clock()

 {

   setTime(0, 0, 0);

 }


//Method to set the time

//The time is set according to the parameters

//Postconditions: hr = hours; min = minutes; sec = seconds

 public void setTime(int hours, int minutes, int seconds)

 {

   if(0 <= hours && hours < 24)

    hr = hours;

   else

    hr = 0;


   if(0 <= minutes && minutes < 60)

    min = minutes;

   else

    min = 0;


   if(0 <= seconds && seconds < 60)

    sec = seconds;

   else

     sec = 0;

 }

  

 public void getTime (int hours, int minutes, int seconds) {

 hours = hr;

 minutes = min;

 seconds = sec;

 }

 


//Method to return the hours

//Postconditions: the value of hr is returned

 public int getHours()

 {

    return hr;

 }


//Method to return the minutes

//Postconditions: the value of min is returned

 public int getMinutes()

 {

    return min;

 }


//Method to return the seconds

//Postconditions: the value of sec is returned

 public int getSeconds()

 {

    return sec;

 }


//Method to print the time

//Postconditions: Time is printed in the form hh:mm:ss

 public void printTime()

 {

    if(hr < 10)

      System.out.print("0");

      System.out.print(hr + ":");


    if(min < 10)

      System.out.print("0");

    System.out.print(min + ":");


    if(sec < 10)

      System.out.print("0");

    System.out.print(sec);

 }


//Method to increment the time by one second

//Postconditions: The time is incremented by one second

//If the before-increment time is 23:59:59, the time

//is reset to 00:00:00

 public void incrementSeconds()

 {

    sec++;

    if(sec > 59)

    {

      sec = 0;

      incrementMinutes(); //increment minutes

    }

 }


//Function to increment the time by one minute

//Postconditions: The time is incremented by one minute

//If the before-increment time is 23:59:53, the time

//is reset to 00:00:53

 public void incrementMinutes()

 {

    min++;

    if(min > 59)

    {

      min = 0;

      incrementHours(); //increment hours

    }

 }

  

 public void addTimeMinute(int minutes) { //new

for (int i=0; i

incrementMinutes();

}


//Method to increment the time by one hour

//Postconditions: The time is incremented by one hour

//If the before-increment time is 23:45:53, the time

//is reset to 00:45:53

 public void incrementHours()

 {

   hr++;

   if(hr > 23)

     hr = 0;

 }


//Function to compare the two times

//Postconditions: Returns true if this time is equal to

//        otherTime; otherwise returns false

 public boolean equals(Clock otherClock)

 {

   return(hr == otherClock.hr

       && min == otherClock.min

       && sec == otherClock.sec);

 }


//Method to copy time

//Postcondition: The data members of otherTime are copied

//        into the correspoding data members of

//        this time.

//        hr = otherTime.hr; min = otherTime.min;

//        sec = otherTime.sec;

 public void makeCopy(Clock otherClock)

 {

   hr = otherClock.hr;

   min = otherClock.min;

   sec = otherClock.sec;

 }


//Method to return a copy of time

//Postcondition: A copy of the object is created

//        and a reference of the copy is returned

 public Clock getCopy()

 {

   Clock temp = new Clock();


   temp.hr = hr;

   temp.min = min;

   temp.sec = sec;


   return temp;

 }


 public String toString()

 {

   String str = "";


   if(hr < 10)

     str = "0";

   str = str + hr + ":";


   if(min < 10)

     str = str + "0" ;

   str = str + min + ":";


   if(sec < 10)

     str = str + "0";

   str = str + sec;


   return str;

 }

  

 public int durationSec (Clock stopA) { //new

int durSec, durMin, durHour;

boolean borrowHour=false, borrowMin=false;

Clock stop;


stop=stopA;

if (stop.sec >= sec)durSec=stop.sec-sec;

else {

durSec=((stop.sec+60) - sec);

borrowMin=true;

}


if (borrowMin)

stop.min-=1;

if (stop.min >= min)durMin=(stop.min-min);

else {

durMin=((stop.min+60) - min);

borrowHour=true;

}


if (borrowHour)

stop.hr-=1;

durHour=(stop.hr - hr);


return (durHour*60)+durMin; //+(int)(durSec/60.0);

}

  

 public boolean equalTime(Clock otherClock) {

return (hr == otherClock.hr && min == otherClock.min && sec == otherClock.sec);

}


public boolean lessThan (Clock otherClock) { //new

if (hr < otherClock.hr) return true;

else if (hr == otherClock.hr) {

if (min < otherClock.min) return true;

else if (min == otherClock.min) {

if (sec == otherClock.sec) return true;

}

}

return false;

}


  

}




----------------------------------------------------------------------------------------------------------------------------------------------------------




public class Customer {

Clock time = new Clock ();

int serviceType;


public Customer (Clock tm, int sType)

 {

   time.setTime(tm.getHours(),tm.getMinutes(),tm.getSeconds());

   serviceType = sType;

 }


public Customer()

 {

   time.setTime(0,0,0);

 serviceType =0;  

 }


public int getSeviceType()

 {

 int temp;

       temp=this.serviceType;


 return temp;

 }


public int setSeviceType()

 {

 int temp;

       temp=this.serviceType;


 return temp;

 }


 public Customer CopyCustomer()

 {

   Customer temp = new Customer();


   //temp.time.getTime(this.time.getHours(), this.time.getMinutes(), this.time.getSeconds()); 

   temp.time = time.getCopy();

   temp.serviceType= getSeviceType();

         temp.toString();

   return temp;

 }


 public String toString()

 {

String str;


  //System.out.print("Customer arrival time: " );

  str = this.time.toString();  

  str = str + " (" + serviceType + ") ";

        return str;

}

}





-----------------------------------------------------------------------------------------------------------------------------------------------



import java.util.*;


public class DEFWashMachine {

  //write your codes here


}





----------------------------------------------------------------------------------------------------------------------------------------------------



/******************************************************************************

 * Compilation: javac Queue.java

 *

 * The Queue class represents a first-in-first-out (FIFO) queue of generic items.

 * It supports the usual enqueue and dequeue operations, along with methods for

 * peeking at the top item, testing if the queue is empty, getting the number of

 * items in the queue, and iterating over the items in FIFO order.

 *

 * For additional documentation, see http://introcs.cs.princeton.edu/43stack of

 * Introduction to Programming in Java: An Interdisciplinary Approach

 *by Robert Sedgewick and Kevin Wayne.

 *

 * @author Robert Sedgewick

 * @author Kevin Wayne

 *

 ******************************************************************************/


import java.util.Iterator;

import java.util.NoSuchElementException;


public class Queue implements Iterable {

  private int n;     // number of elements on queue

  private Node first;  // beginning of queue

  private Node last;   // end of queue


  // helper linked list class

  private class Node {

    private Item item;

    private Node next;

  }


  /**

   * Initializes an empty queue.

   */

  public Queue() {

    first = null;

    last = null;

    n = 0;

  }


  /**

   * Returns true if this queue is empty.

   *

   * @return {@code true} if this queue is empty; {@code false} otherwise

   */

  public boolean isEmpty() {

    return first == null;

  }


  /**

   * Returns the number of items in this queue.

   *

   * @return the number of items in this queue

   */

  public int size() {

    return n;

  }


  /**

   * Returns the number of items in this queue.

   *

   * @return the number of items in this queue

   */

  public int length() {

    return n;

  }


  /**

   * Returns the item least recently added to this queue.

   *

   * @return the item least recently added to this queue

   * @throws NoSuchElementException if this queue is empty

   */

  public Item peek() {

    if (isEmpty()) throw new NoSuchElementException("Queue underflow");

    return first.item;

  }


  /**

   * Add the item to the queue.

   */

  public void enqueue(Item item) {

    Node oldlast = last;

    last = new Node();

    last.item = item;

    last.next = null;

    if (isEmpty()) first = last;

    else      oldlast.next = last;

    n++;

  }


  /**

   * Removes and returns the item on this queue that was least recently added.

   *

   * @return the item on this queue that was least recently added

   * @throws NoSuchElementException if this queue is empty

   */

  public Item dequeue() {

    if (isEmpty()) throw new NoSuchElementException("Queue underflow");

    Item item = first.item;

    first = first.next;

    n--;

    if (isEmpty()) last = null;  // to avoid loitering

    return item;

  }


  /**

   * Returns a string representation of this queue.

   *

   * @return the sequence of items in FIFO order, separated by spaces

   */

  public String toString() {

    StringBuilder s = new StringBuilder();

    for (Item item : this) {

      s.append(item);

      s.append(' ');

    }

    return s.toString();

  }



  /**

   * Returns an iterator that iterates over the items in this queue in FIFO order.

   *

   * @return an iterator that iterates over the items in this queue in FIFO order

   */

  public Iterator iterator() {

    return new ListIterator();

  }


  // an iterator, doesn't implement remove() since it's optional

  private class ListIterator implements Iterator {

    private Node current = first;


    public boolean hasNext() { return current != null;           }

    public void remove()   { throw new UnsupportedOperationException(); }


    public Item next() {

      if (!hasNext()) throw new NoSuchElementException();

      Item item = current.item;

      current = current.next;

      return item;

    }

  }

}

DEF Wash Machine - User Input Problem Description The DEF Wash Machine problem will use the same problem description as the worked example of ABC Wash Machine with regard the DEF Wash Machine provides two types of services: Type 1: normal wash (takes 6 minutes for every service) Type 2: wash and polish (takes 10 minutes for every service). The owner of the DEF Wash Machine would like to know the statistical information as below: Total customers: Number of customers for service of type 1: Number of customers for service of type 2: Longest customer waiting time: < Longest_waiting_time> Average customer waiting time: < Average_waiting_time> ** Your task is to modify the worked-example of ABC Wash Machine and print out the above statistical information. Input Customer arrival time and service type. Each of line represent minutes and service type (1 or 2). 42 11 92 42 71 61 Sample Output Total customers: 5 Number of customers for service of type 1: 2 Number of customers for service of type 2: 3 Longest customer waiting time: 15 minutes Average customer waiting time: 8.40 minutes m Clock.java Customer.java DEFWashMachine.java Queue.java

Step by Step Solution

3.50 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

It looks like you have provided code for a Clock class a Customer class and a Queue class To modify the Clock class to print out statistical informati... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago