Question: Language must be Java Complexity Dynamic arrays Lists Hashing Sorting Prerequisites to work with Java Java SE Development Kit (JDK) Download at http://www.oracle.com/technetwork/java/javase/downloads/index.html - Installation

Language must be Java Complexity Dynamic arrays Lists Hashing Sorting Prerequisites towork with Java Java SE Development Kit (JDK) Download at http://www.oracle.com/technetwork/java/javase/downloads/index.html -Installation (see moodle for installation instructions) - Test installation * Open terminaland type java -version * If you receive information about the javaLanguage must be Java

Complexity Dynamic arrays Lists Hashing Sorting Prerequisites to work with Java Java SE Development Kit (JDK) Download at http://www.oracle.com/technetwork/java/javase/downloads/index.html - Installation (see moodle for installation instructions) - Test installation * Open terminal and type java -version * If you receive information about the java installation, everything is fine Integrated Development Environment (IDE) - eclipse Any text editor is fine to write Java code, but life gets much easier with an appropriate tool. * Syntax highlighting * Auto complete * Error recognition * A debugger that lets you interrupt the execution of your code in order to find errors. - Download at https://www.eclipse.org/downloads/ Data Structures for Sequences Queue import java.util. ArrayDeque; import java.util. Queue; Queue q = new ArrayDequeue (); // "E" can be any type of Object 4.add(E element) // add element at the front E element - q.poll() Il remove and return element at the back q.isEmpty ( ) // return true if empty. false otherwise Stack import java.util. Stack; Stack S = new Stack(); s. push (E element) E element - s.pop() s.isEmpty() // "E" can be any type of Object // add element at the front Il remove and return element at the front 1/ return true if empty, false otherwise Double LinkedList 2 import java.util.LinkedList: LinkedList 1 = new LinkedList(); 1.add(E element) 1. add (int index, E element) 1. contains (E element) E element - 1.get(int index) 1.remove(int index) 1. isEmpty() 1. size() // "E" can be any type of Object // add element in at the front 17 add element at the specified index // returns true if element is in the list 1/ return element at specified index 1/ remove element at specified intex // return true if empty. false otherwise // return the number of elements in the list Literature The structure and contents of our course is guided by the official Java tutorial by oracle. https://docs.oracle.com/javase/tutorial/java/TOC.html Tutorial 10: Java - Ice Skating Rink *** Develop a simple application to manage an ice skating rink. Every skater has a name and an identifier number, the system keeps track of the skaters on the ice rink. The ice rink has a limited capacity, therefore every skater arriving while the rink is full has to wait in a line until someone leaves. When this happens, the first skater in the line gets onto the ice rink. If the ice rink is not at its full capacity, the line must be empty. 1. Create a new project and add a new package named "tutorial". In this package do the following. 2. Create a new class called IceSkater, containing the following: (a) a private attribute String name (b) a private attribute int id (c) a public constructor that initializes name and id (d) public methods getName() and getId(). 3. Create a new class IceRink, containing the following: (a) a private attribute int capacity (b) a private attribute LinkedList skating, that keeps track of all the skaters on the ice rink (c) a private attribute Queue waiting, that keeps track of all the skaters waiting to get on the ice ring (why are we using a queue and not a stack?) (Important! You have to import java.util.Queue and java.util.LinkedList in this class. When needed, Eclipse will automatically do it if you click on the "lightbulb with a cross" symbol(s) on the left of the code) (d) a public constuctor that takes the capacity as input and initializes skating (with dimen- sion equal to capacity) and waiting (you can use any implementation of Queue, like ArrayQueue or LinkedList) (e) a public method void skaterComing (IceSkater skater) that does the following: i. if there is enough space on the rink, it adds skater to skating and prints "Welcome to the ice skating rink, skater ii. otherwise, it adds skater to waiting and prints "skater, the ice rink is full, please wait in the line" (replace skater with his/her actual name) 3 (f) a public method void skaterLeaving (IceSkater skater), that does the following: i. scrolls through skating to find skater, removes it and prints "Goodbye skater!" (if the skater is not found nothing should happen) ii. if waiting is not empty, its first element is popped (function poll() in Java) and added to skating. Evenutally "skater, you can now go to the ice rink!" is printed (replace skater with his/her actual name) 4. Create the main class called IceSkatingMain and add the following code in the main() method: Ice Rink rink = new Ice Rink (2); Ice Skater ann new Ice Skater ("Ann", 2); Ice Skater bob = new Ice Skater ("Bob", 1); Ice Skater cho = new Ice Skater ("Cho", 3); Ice Skater deb = new Ice Skater ("Deb", 4); Ice Skateredd = new Ice Skater ("Edd", 5); rink. skater Coming (ann); rink.skater Coming (bob); rink.skater Coming (cho); rink.skaterLeaving (ann); rink.skater Coming (deb); rink.skater Coming (edd); rink.skaterLeaving (cho); rink.skaterleaving (bob); 5. Run the code. What happens? Homework 10: Java Backpack *** Implement a system simulating a backpack. The items in the backpack are stacked upon one another. This means that to take out an item, one has to extract all the other ones on top of it first. The temporary extracted items are put on the floor until the desired item is removed. Then, the items on the floor are put back in the backpack such that the order in which they were extracted it the same order in which they are put it. (The first item that was extracted is the first item to get back in, and so on). 1. Create a new Java project and add a package named "exercise" in it (you should not have problems doing this by now, if you have troubles take a look at the previous sheets) 2. Create a class Backpack containing the following: (a) a private attribute Stack items, which contains the items in the backpack. (The items are modeled as strings) You have to import the class Stack. You can either use the Eclipse tool (lightbulb that appears when needed) or add "import java.util.Stack;" at the beginning of the class, right below "package exercise;" (b) a private attribute Stack floor, which contains the items which are temporary put on the floor to reach the desired item. (c) a public constructor that initializes items and floor. (E.g, items = new Stack()) (d) a public method void put In (String item), which adds the item in the backpack. (e) a public method void takeOut(String item), which removes the item item from the backpack. All items on top of the desired item are first put on the floor and then back in the backpack. i. For each extracted item: 4 A. print "I put item on the floor" if the item is not the desired one. B. print "item found!" if the item is the desired one. Suggestion! To check if a Stack or a Queue is empty, use isEmpty() Suggestion! To check if two strings are the same, use stringi.equals(string2) ii. If the bottom of the backpack is reached, but the item could not be found, print "item not in the backpack". iii. put all the items on the floor back into the backpack. The order in which they are put in must be the same order in which they were extracted (the first item that was extracted is the first item to get back in, and so on). At every step, "I put item back int the backpack" must be printed. (Always replace item with their actual string) 3. Create a main class called Main and in the main() method add the following: Backpack backpack = new Backpack(); backpack. put In ("sweater"); backpack. putin ("shirt"); backpack. putin ("socks"); backpack. put In ("shoes"); System.out.println(); backpack.takeOut("shirt"); System.out.println(); backpack.takeOut("sweater"); System.out.println(); backpack. takeOut("shirt"); 4. Run the code. What happens? 5. What would happen if we used a Queue to model the floor? 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!