Question

In: Computer Science

import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function...

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);
}
}

Solutions

Expert Solution

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......


Related Solutions

import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the...
import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin ProjectList demo program");    // 1. TO DO: Describe your project (1 Pt) System.out.println("Project: . . . . . . \n"); System.out.println("Create a LinkedList to store the tasks"); // 2. TO DO: Declare a LinkedList of String objects called "tasks" (1 Pt)       System.out.println("Add initial tasks into the list"); // 3. TO DO: Add initial...
import java.util.LinkedList; public class StudentLinkedList { public static void main(String[] args) { LinkedList<Student> linkedlist = new...
import java.util.LinkedList; public class StudentLinkedList { public static void main(String[] args) { LinkedList<Student> linkedlist = new LinkedList<Student>(); linkedlist.add(new Student("Ahmed Ali", 20111021, 18, 38, 38)); linkedlist.add(new Student("Sami Kamal", 20121021, 17, 39, 35)); linkedlist.add(new Student("Salem Salim", 20131021, 20, 40, 40)); linkedlist.add(new Student("Rami Mohammed", 20111031, 15, 35, 30)); linkedlist.add(new Student("Kim Joe", 20121024, 12, 32, 32)); linkedlist.addFirst(new Student("Hadi Ali", 20111025, 19, 38, 39)); linkedlist.addLast(new Student("Waleed Salim", 20131025, 10, 30, 30)); linkedlist.set(0, new Student("Khalid Ali", 20111027, 15, 30, 30)); linkedlist.removeFirst(); linkedlist.removeLast(); linkedlist.add(0, new Student("John Don",...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
import java.util.ArrayList; import java.util.Collections; public class BirthdayList { /** * This is the main process for...
import java.util.ArrayList; import java.util.Collections; public class BirthdayList { /** * This is the main process for class BirthdayList */ public static void main() { System.out.println("\n\tBegin Birthday List Program\n");    System.out.println("Declare an ArrayList for Birthday objects"); // 1. TO DO: Declare an ArrayList to store Birthday objects (3 Pts)       // 2. TO DO: Replace the xxx.xxxx() with the appropriate method (2 Pts) System.out.printf("\nBirthday List is empty: %s\n", xxx.xxxx() ? "True" : "False");    System.out.println("Add at least five Birthdays to...
import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process...
import java.util.ArrayList; import java.util.Collections; import java.lang.Exception; public class ItemList { /** This is the main process for the project */ public static void main () { System.out.println("\n\tBegin Item List Demo\n"); System.out.println("Declare an ArrayList to hold Item objects"); ArrayList<Item> list = new ArrayList<Item>(); try { System.out.println("\n Add several Items to the list"); list.add(new Item(123, "Statue")); list.add(new Item(332, "Painting")); list.add(new Item(241, "Figurine")); list.add(new Item(126, "Chair")); list.add(new Item(411, "Model")); list.add(new Item(55, "Watch")); System.out.println("\nDisplay original Items list:"); listItems(list); int result = -1; // 1....
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        } System.out.println(""+getAvg(new_stack));    }     public static int getAvg(Stack s) {        //TODO: Find the average of the elements in the...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {       ...
import java.util.Stack; import java.util.Scanner; class Main { public static void main(String[] args)    {        Stack<Integer> new_stack = new Stack<>();/* Start with the empty stack */        Scanner scan = new Scanner(System.in);        int num;        for (int i=0; i<10; i++){//Read values            num = scan.nextInt();            new_stack.push(num);        }        int new_k = scan.nextInt(); System.out.println(""+smallerK(new_stack, new_k));    }     public static int smallerK(Stack s, int k) {       ...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT