I need help in JAVA please. Will give thumb up if correct. Do
not copy from other answers if you do not know how to solve. Thank
you!
Grandma's house has a long skinny driveway. When the first guests arrive, they enter the driveway and park nearest the garage. The next guest parks behind that person and so on. At the end of the visit, the cars have to come off the driveway in reverse order. The last person to pull in, has to be the first to pull out. This mimics a queue. Write a program to track the cars in grandma's driveway. Steps: 1) Create a class Car. a) It must have private attributes of Make, Model, Color and License Plate all of which should be strings. b) It must have a constructor that takes in the 4 attributes and sets the object variables. c) It must have an override of toString (java) or ToString (C#) 2) Create a DrivewayNode class. a) It must have two attributes, one to hold a car, the other to hold a link to another DrivewayNode. The car should be private, while the link should be public b) A constructor which takes no parameters and sets the link to null c) A constructor which takes a car and sets the object's car to the car you took in, and sets the link to null. d) A method called getCar which returns a car 3) Create a Driveway Class. (This will be a linked list of cars in the driveway) a) It must have a private attribute called entrance which is of type DrivewayNode. b) It must have a method called addCar which takes in a Car and adds it to the Linked List. c) It must have a method called removeCar which returns a Car. If it's called when no car is in the driveway, it should throw an exception with the message "Empty Driveway" 4) Write a Main method: a) Create a driveway object b) Add 3 cars to it: i) A black Ford F150 license plate ABC123 ii) A silver Nissan Sentra license plate XYZ123 iii) A red Honda Civic license plate DEF890 c) Call remove car 4 times, each time print out the car that you got. Note they should return in the correct order. Handle any problems. Sample Output: I'm a Red Honda Civic I'm a Silver Nissan Sentra I'm a Black Ford F150
Empty Driveway Assignment 13B: A queue is a very useful data structure. A common use is when you have a bunch of tasks (jobs) that need to be done, but you don't have enough time to do them all immediately. Typically you put them into a queue. When you are ready to start working on your tasks, you do the oldest task first from your todo list. Think of a checkout line at a grocery store, the first customer in is the first customer who is checked out. Sometimes however it's necessary to prioritize some of the tasks/jobs in the queue. Think of an Emergency Room in a hospital. In general people are handled in the order they arrive, except if someone comes in with critical needs, they go first. This is called a priority queue. Each task is placed in the queue, but a priority is also assigned. When you pull a task out of the queue, you look for the highest priority In this assignment, you'll write a todo list of tasks that need to be completed before the holidays. When you add each task, you'll specify if it's a low priority, medium priority or high priority. You'll utilize an array of linked lists. The first cell of the array will hold a linked list of high priority items. The second cell will hold a linked list of medium priority items, and the last cell will hold a linked list of low priority items. Steps: 1) Write a Node class which has: a) Private string to hold a task b) A public link called next c) A constructor which takes in a task and correctly initializes the Node d) A method getTask which returns the task string. 2) Write a class Linked List a) Create a head and tail link b) Write a method isEmpty which returns if the list is empty c) Write a method addTask which takes in a string, and adds a new node to the END of the linked list. d) Write a method nextTask() which returns the string from the node at the FRONT of the list, and removes that node. 3) Write a class Priority Queue. a) Create an array of linked lists of size 3 b) Write a constructor which initializes all three cells of the array to new linked lists. c) Write a method addTask which takes in a task (String) and a priority (string). If the priority is high, add it to the linked list in cell 0. If the priority is medium add it to the linked list in cell 1, if the priority is low add it to the linked list in cell 2. d) Write a method getNext Task which takes in nothing, and returns the next task (String) to be performed. It should return the tasks in the correct order. 4) Here is the main method you should use: PriorityQueue myTasks new PriorityQueuel): myTasks.addTask("Rest & Relax over break", "high"); myTasks.addTask("Rate my prof on ratemyprofessor", "low");
myTasks.addTask("Do course evaluations for CSE1322", "medium"); myTasks.addTask("Study for CSE1322L Lab Final", "high"); myTasks.addTask("Plan trip home for holidays", "low"); myTasks.addTask("Study for CSE1322 Final", "high"); myTasks.addTask("Do course evaluations for CSE1322L","medium"); for(int i=0;i<8;i++) { //If you are Java: System.out.println(myTasks.getNextTask(); // If you are C#: Console.WriteLine(myTasks.getNextTask(); } Sample Output: Rest & Relax over break Study for CSE1322L Lab Final Study for CSE1322 Final Do course evaluations for CSE1322 Do course evaluations for CSE1322L Rate my prof on ratemyprofessor Plan trip home for holidays No tasks left
I need help in JAVA please. Will give thumb up if correct. Do not copy from other answers if you do not know how to solv
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am