Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help writing this program CHECKOUT AREA package PJ3; import java.util.*; //

ID: 3534621 • Letter: N

Question

need help writing this program

CHECKOUT AREA

package PJ3;


import java.util.*;


//--------------------------------------------------------------------------

//

// Define simulation queues in a checkout area. Queues hold references to Customer

// and Cashier objects

//

// Customer (FIFO) queue is used to hold waiting customers. If the queue is too long

// (i.e. > customerQLimnit), customer goes away without entering customer queue

//

// There are several cashiers in a checkout area. Use PriorityQueue to

// hold BUSY cashiers and FIFO queue to hold FREE cashiers,

// i.e. a cashier that is FREE for the longest time should start be used first.

//

// To handle cashier in PriorityQueue, we need to define comparator

// for comparing 2 cashier objects. Here is a constructor from Java API:

//

// PriorityQueue(int initialCapacity, Comparator<? super E> comparator)

//

// For priority queue, the default compare function is "natural ordering"

// i.e. for numbers, minimum value is returned first

//

// User can define own comparator class for PriorityQueue.

// For cashier objects, we like to have smallest end busy interval time first.

//

// The following class define compare() for two cashiers :


class CompareCashier implements Comparator<Cashier>{

// overide compare() method

public int compare(Cashier o1, Cashier o2) {

return o1.getEndBusyIntervalTime() - o2.getEndBusyIntervalTime();

}

}


// DO NOT ADD NEW METHODS OR DATA FIELDS

class CheckoutArea {


// Private data fields:

// define one priority queue

private PriorityQueue <Cashier> busyCashierQ;


// define two FIFO queues

private Queue<Customer> customerQ;

private Queue<Cashier> freeCashierQ;


// define customer queue limit

private int customerQLimit;



// Constructor

public CheckoutArea()

{

// add statements

}


// Constructor

public CheckoutArea(int numCashiers, int customerQlimit, int startCashierID)

{

// use ArrayDeque to construct FIFO queue objects


// construct PriorityQueue object

// overide compare() in Comparator to compare Cashier objects

busyCashierQ= new PriorityQueue<Cashier>( numCashiers,

new CompareCashier());


// initialize customerQlimit

// Construct Cashier objects and insert into FreeCashierQ

// add statements

}


public Cashier removeFreeCashierQ()

{

// remove and return a free cashier

// Add statetments

return null;

}


public Cashier removeBusyCashierQ()

{

// remove and return a busy cashier

// Add statetments

return null;

}


public Customer removeCustomerQ()

{

// remove and return a customer

// Add statetments

return null;

}


public void insertFreeCashierQ(Cashier cashier)

{

// insert a free cashier

// Add statetments

}


public void insertBusyCashierQ(Cashier cashier)

{

// insert a busy cashier

// Add statetments

}


public void insertCustomerQ(Customer customer)

{

// insert a customer

// Add statetments

}


public boolean emptyFreeCashierQ()

{

// is freeCashierQ empty?

// Add statetments

return false;

}


public boolean emptyBusyCashierQ()

{

// is busyCashierQ empty?

// Add statetments

return false;

}


public boolean emptyCustomerQ()

{

// is customerQ empty?

// Add statetments

return false;

}


public int numFreeCashiers()

{

// get number of free cashiers

// Add statetments

return 0;

}


public int numBusyCashiers()

{

// get number of busy cashiers

// Add statetments

return 0;

}


public int numWaitingCustomers()

{

// get number of customers

// Add statetments

return 0;

}


public Cashier getFrontBusyCashierQ()

{

// get front of busy cashiers

// "retrieve" but not "remove"

// Add statetments

return null;

}


public boolean isCustomerQTooLong()

{

// is customerQ too long?

// Add statetments

return false;

}


public void printStatistics()

{

System.out.println(" # waiting customers : "+numWaitingCustomers());

System.out.println(" # busy cashiers : "+numBusyCashiers());

System.out.println(" # free cashiers : "+numFreeCashiers());

}


public static void main(String[] args) {


// quick check


CheckoutArea sc = new CheckoutArea(4, 5, 1001);

Customer c1 = new Customer(1,18,10);

Customer c2 = new Customer(2,33,10);

Customer c3 = new Customer(3,21,10);

Customer c4 = new Customer(3,37,10);

sc.insertCustomerQ(c1);

sc.insertCustomerQ(c2);

sc.insertCustomerQ(c3);

System.out.println(""+sc.customerQ);

System.out.println("Remove customer:"+sc.removeCustomerQ());

System.out.println("Remove customer:"+sc.removeCustomerQ());

System.out.println("Remove customer:"+sc.removeCustomerQ());


System.out.println(""+sc.freeCashierQ);

Cashier p1=sc.removeFreeCashierQ();

Cashier p2=sc.removeFreeCashierQ();

Cashier p3=sc.removeFreeCashierQ();

Cashier p4=sc.removeFreeCashierQ();

System.out.println("Remove free cashier:"+p1);

System.out.println("Remove free cashier:"+p2);

System.out.println("Remove free cashier:"+p3);

System.out.println("Remove free cashier:"+p4);


p1.freeToBusy (c1, 13);

p2.freeToBusy (c2, 13);

p3.freeToBusy (c3, 13);

p4.freeToBusy (c4, 13);

sc.insertBusyCashierQ(p1);

sc.insertBusyCashierQ(p2);

sc.insertBusyCashierQ(p3);

sc.insertBusyCashierQ(p4);

System.out.println(""+sc.busyCashierQ);

p1=sc.removeBusyCashierQ();

p2=sc.removeBusyCashierQ();

p3=sc.removeBusyCashierQ();

p4=sc.removeBusyCashierQ();

System.out.println("Remove busy cashier:"+p1);

System.out.println("Remove busy cashier:"+p2);

System.out.println("Remove busy cashier:"+p3);

System.out.println("Remove busy cashier:"+p4);


}



};

CUSTOMER CLASS

// DO NOT ADD NEW METHODS OR DATA FIELDS


package PJ3;


class Customer

{

private int customerID;

private int checkoutDuration;

private int arrivalTime;


Customer()

{

customerID = 0;

checkoutDuration = 0;

arrivalTime = 0;

// add statements

}


Customer(int customerid, int checkoutduration, int arrivaltime)

{

customerID = customerid;

checkoutDuration = checkoutduration;

arrivalTime = arrivaltime;// add statements

}


int getCheckoutDuration()

{

// add statements

return checkoutDuration;

}


int getArrivalTime()

{

// add statements

return arrivalTime;

}


int getCustomerID()

{

return customerID;

}


public String toString()

{

return ""+customerID+":"+checkoutDuration+":"+arrivalTime;


}


public static void main(String[] args) {

// quick check!

Customer mycustomer = new Customer(20,30,40);

System.out.println("Customer Info:"+mycustomer);


}

}


CASHIER CLASS

// DO NOT ADD NEW METHODS OR DATA FIELDS!


package PJ3;


class Cashier {


// define constants for representing intervals

static int BUSY = 1;

static int FREE = 0;


// start time and end time of current interval

private int startTime;

private int endTime;


// cashier id and current customer which is served by this cashier

private int cashierID;

private Customer currentCustomer;


// for keeping statistical data

private int totalFreeTime;

private int totalBusyTime;

private int totalCustomers;


// Constructor

Cashier()

{

cashierID = 0;// add statements

}



// Constructor with cashier id

Cashier(int cashierId)

{

cashierID = cashierId;// add statements

}


// accessor methods


int getCashierID ()

{

return cashierID;

}


Customer getCustomer()

{

// add statements

return currentCustomer;

}


// need this to setup pririty queue

int getEndBusyIntervalTime()

{

// return end time of busy interval

// add statements

return currentCustomer.getCheckoutDuration();

}


// functions for state transition

// FREE -> BUSY :

void freeToBusy (Customer currentCustomer, int currentTime)

{

// Main goal : switch from free interval to busy interval

//

// end free interval, start busy interval

// steps : update totalFreeTime

// set startTime, endTime, currentCustomer,

// update totalCustomers

totalFreeTime = currentTime - totalBusyTime;

currentCustomer = getCustomer();

startTime = currentTime;

endTime = currentTime + currentCustomer.getCheckoutDuration();

totalCustomers++;


// add statements

}


// BUSY -> FREE :

Customer busyToFree ()

{

// Main goal : switch from busy interval to free interval

//

// steps : update totalBusyTime

// set startTime

// return currentCustomer

totalBusyTime =+ currentCustomer.getCheckoutDuration();


// add statements

return currentCustomer;

}


// need this method at the end of simulation to update cashier data

void setEndIntervalTime (int endsimulationtime, int intervalType)

{

// for end of simulation

// set endTime,

// for FREE interval, update totalFreeTime

// for BUSY interval, update totalBusyTime


// add statements

}


// functions for printing statistics :

void printStatistics ()

{

// print cashier statistics, see project statement


System.out.println(" Cashier ID : "+cashierID);

System.out.println(" Total free time : "+totalFreeTime);

System.out.println(" Total busy time : "+totalBusyTime);

System.out.println(" Total # of customers : "+totalCustomers);

if (totalCustomers > 0)

System.out.format(" Average checkout time : %.2f%n ",(totalBusyTime*1.0)/totalCustomers);

}


public String toString()

{

return "Cashier:"+cashierID+":"+startTime+"-"+endTime+":Customer:"+currentCustomer;

}


public static void main(String[] args) {

// quick check

Customer mycustomer = new Customer(20,30,40);

Cashier mycashier = new Cashier(5);

mycashier.freeToBusy (mycustomer, 13);

System.out.println(mycashier);


}


};

CHECKOUTAREA


so far so good or no? please any assistance appreciated

Explanation / Answer

package org.kodejava.example.util.zip;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZippingFileExample {
public static void main(String[] args) {
String source = "data.txt";
String target = "data.zip";

try {
ZipOutputStream zos = new ZipOutputStream(
new FileOutputStream(target));

//
// Create input stream to read file from resource folder.
//
Class clazz = ZippingFileExample.class;
InputStream is = clazz.getResourceAsStream("/" + source);

//
// Put a new ZipEntry in the ZipOutputStream
//
zos.putNextEntry(new ZipEntry(source));

int size;
byte[] buffer = new byte[1024];

//
// Read data to the end of the source file and write it
// to the zip output stream.
//
while ((size = is.read(buffer, 0, buffer.length)) > 0) {
zos.write(buffer, 0, size);
}

zos.closeEntry();
is.close();

//
// Finish zip process
//
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}