Alabama Aviation College Write a Program Code Java Programming Task
Question 1-3
Que1.
Implement a Stack
Instructions
note: work should be done in eclipse for all the questions( please download eclipse). send to me zipped if possible
For this assignment, you will implement a Stack data structure. A stack can be implemented in several different ways. It is not inherently a node-based data structure, but you could implement it using nodes if you like.
The most important thing to remember with stacks is the way they push, pop, and peek data.
- push() : adds an element to the top/front of the stack
- pop() : removes the first element from the stack, and returns it.
- peek() : returns the first element from the stack without removing it.
Your stack should be able to support all of these functions. For example, you might have something like the following:
public class Stack { private Node top; public void push(Node newNode) { // your implementation here } public Node pop() { // your implementation here } public Node peek() { // your implementation here } } Ques 2. Instructions For this task, you will have to implement a Linked List, which is a node-based data structure. This will be easier than it seems. Recall that a node-based data structure is simply a collection of "node" objects. Each node object contains a reference to one or more other nodes, and a bit of data. Thus, your node might look like this: public class Node { Node next; Integer data; } Of course, if you wanted to use generics, you could create a generic Node class which used the generic type for the "data" variable too. A LinkedList Class might then look like this: public class LinkedList { Node head; // utility methods }A node for a Linked List might be improved by having an "add()" method with special behavior: when invoked, the "add()" method will traverse the linked list to add a given node to the end of the list. algorithm add is: input: Node newNode -> The new node to add let "currentNode" = head; while current.next != null current = current.next current.next = newNode Ques 3 Introduction In the JavaScript module, you designed a website that would let users convert between one type of unit and another. Now you're going to do the same thing, but in a Java application that runs in the console. Instructions In Eclipse, create a new Java Project named "UnitConverter" In the UnitConverter project, create a package named "main" Inside the main package, create a class named Converter, which has a main(String[]) method. Inside this main(String[]) method, your code should follow this pattern: Create an int variable named menuSelection Inside a while loop, with the condition menuSelection != /*last menu option */Using System.out.println(), print a menu with numbered options. For example:Please select an option: 1. Cups to Teaspoons 2. Miles to Kilometers 3. US Gallons to Imperial Gallons 4. Quit Use a Scanner object to collect the user's menuSelection switch on the selection to collect the user's quanity of the first unit, convert to the second unit, and print the output. note: if the below is difficult to work on then it okay. but make sure the above runs well. that's basically it! But from here, there are a lot of improvements you could make... Break the input collection to a seaprate methodprivate static double collectQuantity(String unit1, String unit2) { ... } Break each unit conversion to a separate methodpublic double convertCelsiusToFarenheit(double qty) { ... } Instead of the user selecting their conversion directly from the first menu, have two layers of menus:Volume conversionsTeaspoons to Tablespoons Teaspoons to Cups ... Distance conversionsFeet to Meters Miles to Kilometers ... ... Quit