Question

Java Programming Stacks Queues Linked List Programming Problems Stack - Implementation. You will be able to...

Java Programming

Stacks

Queues

Linked List

Programming Problems

Stack - Implementation. You will be able to use the push, pop and peek of Stack concept.

Post-Fix calculator - When an arithmetic expression is presented in the postfix form, you can use a stack to evaluate the expression to get the final value. For example: the expression 3 + 5 * 9 (which is in the usual infix form) can be written as 3 5 9 * + in the postfix. More interestingly, post form removes all parentheses and thus all implicit precedence rules.

Program Implementation Requirements

Use the stack concept to create a post-fix calculator.

LinkedList/Queue - Implementation.

New concert tickets are available. You have to enter the names of the people in order to form a line. However, you will later find out that a few people are not eligible to buy tickets because they represent scalpers instead of actual concert goers. You will have to remove those people from the line. A special raffle will be done and the result of the raffle will insert a person to the front of the line. You will have to issue tickets to the first 10 people in line, but there are 15 people total in line. The others will have to put into a waitlist queue for the next available ticket.

Program Implementation Requirements

Use the Linked List (Original Line) and a Queue (waitlist) concept to create this program. The class name will be ConcertTickets. You will have the following methods: insertIntoLine(Person p), removeFromLine(Person p), addToWaitList(Person p), assignedTicket().

.

Homework Answers

Answer #1

Iam doing the first part of the question since the user has not asked for a specific question.

import java.util.*;
import java.lang.*;
import java.io.*;


public class Main {
public static void main(String[] args) {
System.out.println(postfixCalc("3 5 9 * +")); // 48
System.out.println(postfixCalc("1 2 3 * + 4 +")); // 11
System.out.println(postfixCalc("5 2 4 * + 7 -")); // 6
System.out.println(postfixCalc("7 8 + 3 2 + /")); // 3

}
  
// Evaluates the given postfix expression string and returns the result.
// condition is that: expression consists only of integers, +-*/, and spaces in
// proper postfix format such as "3 5 9 * +"
public static int postfixCalc(String exp) {
      Stack<Integer> s1 = new Stack<Integer> ();
       Scanner token = new Scanner(exp);
      
       while (token.hasNext()) {
           if (token.hasNextInt()) {
               s1.push(token.nextInt());
           } else {
               int numb2 = s1.pop();
               int numb1 = s1.pop();
               String str = token.next();
              
               if (str.equals("+")) {
                   s1.push(numb1 + numb2);
               } else if (str.equals("-")) {
                   s1.push(numb1 - numb2);
               } else if (str.equals("*")) {
                   s1.push(numb1 * numb2);
               } else {
                   s1.push(numb1 / numb2);
               }
              
           // "+", "-", "*", "/"
           }
       }
       return s1.pop();
}
}

Output will be :

48

11

6

3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA LinkedList/Queue - Implementation. New concert tickets are available. You have to enter the names of...
JAVA LinkedList/Queue - Implementation. New concert tickets are available. You have to enter the names of the people in order to form a line. However, you will later find out that a few people are not eligible to buy tickets because they represent scalpers instead of actual concert goers. You will have to remove those people from the line. A special raffle will be done and the result of the raffle will insert a person to the front of the...
IN JAVA LANGUAGE Linked List-Based Stack Implementation Implement Stack using a Linked List Use the language...
IN JAVA LANGUAGE Linked List-Based Stack Implementation Implement Stack using a Linked List Use the language library LinkedList Stack methods will call the LinkedList methods You can use string as the object Instead of using an array, as the StackLab did, here you will use a Linked List from your language's library. Implement all the methods of Stack : push(), pop(), size(), printStackDown(), etc, using calls to the linked list methods that correspond to the actions need. In the array...
Stack Queue Program Implement a Stack class using the List Class you developed earlier. Test your...
Stack Queue Program Implement a Stack class using the List Class you developed earlier. Test your Stack class by determining if the following strings have matching open and closing ( ) and/or [ ] and/or { }. To test matches, push open (, [, { onto the stack. Input a close char, pop off the stack and see if input matches symbol form stack.   Use the following data to test your code:                               ( )                               [ ] ( )...
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your...
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your Can class. You need to create a driver that makes several Can objects and places them in alphabetical order in a list. Identify the necessary methods in a List Linked implementation. Look at previous Data Structures (stack or queue) and be sure to include all necessary methods. NOT USE your language's Library List . You will receive zero points. Write a LinkedList class. Include...
Selecting an Implementation We have studied arrays, vectors, and linked lists. Say which you would use...
Selecting an Implementation We have studied arrays, vectors, and linked lists. Say which you would use to implement each situation below. Defend every answer by saying why the answer you chose is better than the other two possibilities. A list of participants at a large public hearing. As each person arrives, their name is entered into the system, where it is appended to the end of the list. Thermometer readings at a weather station. The temperature is recorded every 5...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules of the game are as follows:  The game is played with two (2) players.  There are three (3) different Stacks in the game.  Each turn, a player pushes a disk on top of exactly one of the three Stacks. Players alternate turns throughout the game. Each disk will include some marker to denote to whom it belongs.  At the end...
Java please. Need to use a linked list only. Many people have used pulling petals off...
Java please. Need to use a linked list only. Many people have used pulling petals off roses and tossing them in the air to determine if someone loves them or not. Your sister wants to use roses to determine which one of several suitors she will let take her to the prom. A linked list can be used to represent the prom date suitors. Write a program to simulate her decision and determine her prom date. The simulation will work...
You must implement a dynamic webpage the provides a basic task-list functionality. In particular, you page...
You must implement a dynamic webpage the provides a basic task-list functionality. In particular, you page should provide a user an interface to add and remove a task as well as mark a task as completed. For this version of the assignment, the tasks will be added directly in the HTML page by manipulating the DOM. Moreover, you should maintain an array that stores task details. Each task comprise of three fields: task-title: which is a one-line description of the...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT