Question
[JAVA] PLEASE NO HASHMAPS! CODE NEEDS TO BE SIMPLE! PLEASE SHOW OUTPUT! (1) Print all subsets for a string (2 points) Use java.util.LinkedList to print
[JAVA] PLEASE NO HASHMAPS! CODE NEEDS TO BE SIMPLE! PLEASE SHOW OUTPUT!
(1)Print all subsets for a string (2 points)
Use java.util.LinkedList to print out all subsets for a giving string. Download CState.java from Moodle.
For a given string abcdef, list out all possible nonempty subset string of
abcdef using Queue data structure.
For example: a,ab,b,abc,ac,bc, etc.
(2)Simple simulation (2 points)
Use java.util.LinkedList to create a system to simulate customers being served at the bank. Download Customer.java & Line.java from Moodle.
(a)Assume there is only one service line at the bank and it is first come, first served.
(b)The number of customer arriving at the bank varies from 1 to 5 and the number of tellers available to serve the customer varies from 1 to 4.
(c)Each customer will receive a sequential ID number when he/she join the line. The program should display the message Customer xxx joins the line to indicate the occurrence of the event.
(d)At the same token, when the teller serves the customer, the program should display Customer xxx is being served.
(e)If the line is empty, display Teller waiting.
(f)Simulate the cycle for 10 times as the end of banks business day.
(g)The service line should be empty after the bank is closed.
public class CState {
private String Prefix = new String(); private String Suffix = new String(); public CState (String Pre, String Suff) { Prefix = Pre; Suffix = Suff; } public String pre() { return Prefix; } public String suff() { return Suffix; } }
//******************************************************************* // Customer.java //*******************************************************************
public class Customer { private int id;
//---------------------------------------------------------------- // Creates a customer with the specified id number. //---------------------------------------------------------------- public Customer (int number) { id = number; }
//---------------------------------------------------------------- // Returns a string description of this customer. //---------------------------------------------------------------- public String toString() { return "Customer " + id; } }
//******************************************************************* // Line.java // //*******************************************************************
import java.util.LinkedList;
public class Line { LinkedList queue;
//---------------------------------------------------------------- // Creates a new line based on a queue. //---------------------------------------------------------------- public Line() { queue = new LinkedList(); }
//---------------------------------------------------------------- // Removes a customer from the head of the queue. //---------------------------------------------------------------- public Customer nextCustomer() { return (Customer)queue.removeFirst(); }
//---------------------------------------------------------------- // Adds a customer to the tail of the queue. //---------------------------------------------------------------- public void addCustomer(Customer person) { queue.addLast(person); }
//---------------------------------------------------------------- // Indicates whether the queue is empty. //---------------------------------------------------------------- public boolean isEmpty() { return queue.isEmpty(); }
//---------------------------------------------------------------- // Returns the number of customers in the queue. //---------------------------------------------------------------- public int size() { return queue.size(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started