In: Computer Science
import java.util.LinkedList;
import java.util.Queue;
import java.time.*;
public class CheckOutLine
{
/** This is the main function for the program */
public static void main()
{
System.out.println("\n\tBegin CheckOutLine Demo\n");
System.out.println("\nCreating a Queue called \"register\" based
on a LinkedList");
Queue<Customer> register = new
LinkedList<Customer>();
System.out.println("\nAdding Customers to the Register
queue");
// 1. TO DO: add five or more customers to the register line (5
Pts)
// format: register.add(new Customer(name, checkout time));
System.out.printf("Register line has %d customers\n",
register.size());
System.out.println("\nDeclare the LocalTime start time as
10:00");
LocalTime lt = LocalTime.parse("10:00:00.00");
System.out.println("Start checking out Customers at the register at
" + lt);
// 2. TO DO: code a while loop statement to process all the
// customers in the queue (3 Pts)
while(. . . . . . .)
{
Customer cust = register.poll();
lt = lt.plus(Duration.ofMinutes(cust.getMinutes()));
System.out.println(cust.toString() + " checked out at " +
lt);
}
System.out.println("\n\tEnd CheckOutLine Demo\n");
}
}
import java.lang.String;
public class Customer
{
private String name;
private int minutes;
/**
* Constructor for objects of class Customer
* @param name - customer name
* @param minutes - number of minutes to check out at register
*/
public Customer(String name, int minutes)
{
this.name = name;
this.minutes = minutes;
}
/**
* This method returns the minutes for check out
* @return minutes - the number of minutes to spend checking out at
the register
*/
public int getMinutes()
{
return minutes;
}
/**
* This method overrides the toString method of the Object
class
* to return the customer information as a String for display
* @return Customer information as a String
*/
@Override
public String toString()
{
return String.format("%-20s %3d minutes ", name, minutes);
}
}
Code:
package Assignments;
import java.time.Duration;
import java.time.LocalTime;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
class Customer {
private String name;
private int minutes;
/**
* Constructor for objects of class Customer
* @param name - customer name
* @param minutes - number of minutes to check out at
register
*/
public Customer(String name, int minutes)
{
this.name = name;
this.minutes = minutes;
}
/**
* This method returns the minutes for check out
* @return minutes - the number of minutes to spend
checking out at the register
*/
public int getMinutes()
{
return minutes;
}
/**
* This method overrides the toString method of the
Object class
* to return the customer information as a String for
display
* @return Customer information as a String
*/
@Override
public String toString()
{
return String.format("%-20s %3d minutes ", name,
minutes);
}
}
public class CheckOutLine {
public static void main(String[] args) {
// TODO Auto-generated method
stub
System.out.println("\n\tBegin
CheckOutLine Demo\n");
System.out.println("\nCreating a
Queue called \"register\" based on a LinkedList");
Queue<Customer> register =
new LinkedList<Customer>();
System.out.println("\nAdding
Customers to the Register queue");
// 1. TO DO: add five or more
customers to the register line (5 Pts)
register.add(new
Customer("mouni",10));
register.add(new
Customer("mounika",20));
register.add(new
Customer("krishna",30));
register.add(new
Customer("krish",20));
register.add(new
Customer("sam",40));
System.out.printf("Register line
has %d customers\n", register.size());
System.out.println("\nDeclare the
LocalTime start time as 10:00");
LocalTime lt =
LocalTime.parse("10:00:00.00");
System.out.println("Start checking
out Customers at the register at " + lt);
// 2. TO DO: code a while loop
statement to process all the
// customers in the queue (3
Pts)
//Iterator<Customer> it=new
register.iterator<Customer>();
while(!register.isEmpty())
{
Customer cust =
register.poll();
lt =
lt.plus(Duration.ofMinutes(cust.getMinutes()));
System.out.println(cust.toString()
+ " checked out at " + lt);
}
System.out.println("\n\tEnd
CheckOutLine Demo\n");
}
}
Note:****I hope your happy with my answer***If you like please give me upvote*****Thank you......