Infix To Postfix And Prefix - Not Ordering Correctly

Jul 28, 2014

So my code works perfectly when I input (a+(c-d) and i get ab+cd- for postfix and *+ab-cd for prefix. However when I input a+b+c for infix i receive abc++ postfix and +a+bc prefix when its supposed to be ab+c+ postfix and ++a b c prefix. So my issue is that any infix input with parenthesis, it converts them correctly, however without parenthesis it does not convert correctly.

import java.util.*;
public class stack {
public static char[] convertToPostfix(char[] infixEx) {
Stack<Character> operatorStack = new Stack<Character>();
char[] postfix = new char[infixEx.length];
int index = 0;

[Code] .....

View Replies


ADVERTISEMENT

Infix To Prefix - Pow Only Takes Int Values Not Doubles

Feb 7, 2014

I am having a problem with infix and prefix ... Here is the code

import java.util.StringTokenizer;
import static java.lang.Math.pow;
import java.util.Stack;
 public class Calculator {
static int precedence(char op) {
switch(op) {

[Code] ....

it says in line 72
possible loss of precision
required: int
found: double
the pow only takes int values?not doubles?how do i fix it?

View Replies View Related

Infix And Postfix Conversion

Feb 25, 2014

Case study : infix to postfix conversion, i don't really know how i could make codes, I can understand what is the meaning of infix and postfix but when it comes of making codes i really have a hard time with it.

View Replies View Related

How Does Prefix And Postfix Change The Answer

Mar 26, 2015

Will the postfix x++ and the prefix --y change the answer for this question?

If x has the value 10 and so does y, then what is the value of (x ++) * (-- y)?

Answer: 11*9

View Replies View Related

Getting Errors When Converting Infix To Postfix

Nov 24, 2014

I need to convert infix To Postfix but have a few errors.

Error msg:

PostFix:
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Unknown Source)
at java.util.Stack.pop(Unknown Source)
at assignment4.infixToPostfix.evaluatePostfix(infixTo Postfix.java:129)
at assignment4.infixToPostfix.main(infixToPostfix.jav a:19)

NB:
129 >>return (double) s1.pop(); AND 19>>>double ans = evaluatePostfix(postfixStr);
Deadline = less than 1 hour

View Replies View Related

Changing Infix To Postfix Notation Using Stacks - How To Utilize Hash Maps

Apr 7, 2014

So I am supposed to be changing infix notation to postfix notation using stacks. This is simply taking a string "3 + 5 * 6" (infix) and turning it into (3 5 6 * +" (postfix).

To do this, we are to scan the string from left to right and when we encounter a number, we just add it to the final string, but when we encounter an operand, we throw it on the stack. Then if the next operand has a higher input precedence than the stack precedence of the operator on the top of the stack, we add that operator to the stack too, otherwise we pop from the stack THEN add the new operator.

I am supposed to be utilizing a hash map but I don't see how you would go about doing this. We are supposed to store operators on the hash map but operators need their own character, input precedence, stack precedence, and rank. How do you use a hash map when you need to tie a character to 3 values instead of just 1? I just don't get it.

The following is our Operator class that we are to use. Another problem is this isn't really supposed to be modified, yet we were given two important variables (inputPrecedence and outputPrecedence) that we can't have nothing to be initialized to and no way of accessing? So that might be where a hash map comes in but I am not sure. I am not very sure on how they exactly work anyway...

public class Operator implements Comparable<Operator>
{
public char operator; // operator
privateint inputPrecedence; // input precedence of operator in the range [0, 5]
privateint stackPrecedence; // stack precedence of operator in the range [-1, 3]

[Code] ....

So my question mostly revolves around how I tie an Operator character to its required values, so I can use it in my code to test two operators precedence values.

My original thought was turn string into character array, but then I would need nested for/while loops to check if it is a number or letter, or if it is an operator and thus result in O(n^2) time

View Replies View Related

Why For Loop Prefix Not Taken Into Consideration

Dec 5, 2014

I was looking at this for loop

for ( int i = 0; i < 10; i++){/*print i*/}

It prints 0..9 - fine.

I then looked at this loop

for ( int i = 0; i < 10; ++i){/*print i*/}

It prints 0..9 - why? From what I understand ++i is a prefix, therefore by the time the for loop condition is checked, shoudln't i start with 1? So 1..9?

If I did this test in a print statement so:

int i=0;
System.out.print(++i) //this prints 1,

so why doesn't this apply in the for loop?

View Replies View Related

Number Sorting Having Prefix Letter

Dec 24, 2014

I had a list of some numbers having a prefix A like A12 , A55, A76 ,A111 ,A888, A88 ,A880 A111 , A11,A1

I need to sort this list so the result would be A1,A11,A12,A55,A76....

How to do this. Can I use arrays.sort method to achieve the same or any other way.

View Replies View Related

Swing/AWT/SWT :: Possible To Use Items In ComboBox To Prefix File Name?

Oct 8, 2014

If I have a comboBox full of id's - is it possible that when I choose said id (click it) it will then transfer over into my textField where I can use that as a prefix for my filename ...

(The file can be created just by having a name in the text field it doesn't need to already exists) ...

View Replies View Related

Evaluating Infix Expressions Using Generic Stacks

May 12, 2014

I am given the task to create a program that evaluates infix expressions using two generic stacks, one operator stack and one value stack.

This is my GenStack.java file:

import java.util.*;
public class GenStack<T>{//T is the type parameter
private Node top;//top of stack
public class Node {//defines each node of stack
T value;
Node next;

[Code] ....

I'm having trouble with the eval and apply methods. The eval method doesn't appear to pickup ')' characters, like it doesn't even see them.

View Replies View Related

Ordering System In Eclipse?

Jul 22, 2014

it gives me an error at the end class part some syntax error insert "}"..

* Course: IT110 - Introduction to Programming
* Filename: MyCustomShirtsPhase1.java
*
* Purpose: Created a simple online ordering system for My Custom Shirts customers
*/
import javax.swing.JOptionPane;

[code]....

View Replies View Related

Swing/AWT/SWT :: GUI Codelines Ordering

Feb 14, 2015

i am studying java from head first java book and yesterday i was working on a program called QuizCardBuilder. what i noticed is that when i changed the order of the lines from the book i get a blank frame with nothing on it.this is my code that gives blank frame

public class QuizCardBuilder{
JFrame frame;
JTextArea question;
JTextArea answer;
JButton nextButton;
ArrayList<QuizCard> cardList;

[code]....

View Replies View Related

Simple Meal Ordering System

Aug 4, 2014

requirments:
meal module -payment module
list of items/vm
single item - delated/add
value meal item
all with prizes
price module
per items
per meal
total

View Replies View Related

Create A Restaurant Ordering System Using JFrame

Oct 14, 2014

How to create a restaurant ordering system using JFrame .....

View Replies View Related

Swing/AWT/SWT :: Action Listeners - Pizza Ordering GUI

Dec 3, 2014

I've got the layout put correctly but I can't seem to get my action listeners to work correctly.

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class PizzaOrderDriver
{
public static void main(String[] args)
{
JCheckBox show1;

[Code] .....

View Replies View Related

PostFix Calculator Project?

Apr 2, 2015

So I am working on a PostFix calculator that is used in command line for a class project, and I am having a little trouble on developing a memory for it. I have been told to create a hashMap and I have researched it and understand the basics of it. I have the calculating method working, but what I am having trouble trying to implement a way for the user to declare variables. For example this what the user should be able to do:

> a = 3 5 + 1 -
7
> bee = a 3 *
21
> a bee +
28

[code]....

I just need to be able to save the answers as a variable the User names, such as the example and let the user be able to use the variables later.

View Replies View Related

Postfix Evaluation Using Stack?

Apr 24, 2014

after i am done calculating everything from numbers stack, i pop the last number and return it... my question is how can i catch an exception if the size of my numbers stack is greater than 1;

public static String evaluate(String input) {
char[] a = input.toCharArray();
if (input.isEmpty())
return "No input";
else if (input.equals(" "))
return "No input";
else if (input.equals(" "))

[code]....

View Replies View Related

Pizza Pickup And Delivery Ordering Java Program

Jul 31, 2014

This is my code for a Pizza Pickup and delivery I am am having a few issues.

public class Internal {
public static void main(String[]args) {
double total2 = 0;
String customerName = " ";
String address = " ";
String phoneNum ="0";

[Code] ....

View Replies View Related

Evaluate Postfix Notation Entered From Keyboard?

Oct 24, 2014

My question is to evaluate a Postfix notation entered from keyboard. I have no errors in my code but it prints only :

Exception in thread "main"

java.util.NoSuchElementException
at ArrayStack.pop(PostFixEvaluation.java:72)
at PostFixEvaluation.evaluatePostfix(PostFixEvaluatio n.java:107)
at PostFixEvaluation.main(PostFixEvaluation.java:140)

I tried many values but it prints the same exception all the time.

Here is my code:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.NoSuchElementException;
interface Stack<E> {
 
[Code] ....

View Replies View Related

Lexicographic Ordering - When Input String Values / No Output Takes Place

Jan 28, 2015

I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s

import java.util.Scanner;
public class Lab03c {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lexi = new Scanner (System.in);
String s1,s2;

[Code] ....

View Replies View Related

Postfix Calculator Doesn't Compute Negative Numbers

Nov 16, 2014

My verify method also always returns false. So I'm given three classes to begin with. Calculator, Expression, and InfixExpression and they are listed below.

The goal is to create a class called PostfixExpression that extends Expression and can read and calculate postfix expressions.

My evaluate() method works for most calculations but when it needs to return a negative value it just returns the positive equivalent.

Also, my verify method always returns false and I can't pinpoint why.

Here's my current code. Some things are commented out for debugging purposes.

import java.util.Scanner;
/**
* Simple calculator that reads infix expressions and evaluates them.
*/
public class Calculator
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[Code] .....

View Replies View Related

Scan Postfix Expression From Left To Right Using Operand Stack

Apr 13, 2015

package hw9;

import java.util.Scanner;
import java.util.Stack;
public class stack {
public static Integer evaluate(String expression) {
Scanner scanner = new Scanner(expression);
Stack <Integer> operands = new Stack<Integer>();

[Code] ....

When I input my expression which has spaces between characters e.g.:10 2 8 * + 3 -, it worked; when I put expression which may not add space between each char e.g.: 3 14+2*7/, the error showed:

Enter a postfix expression: 3 14+2*7/
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at java.util.Stack.pop(Stack.java:84)
at hw9.stack.evaluate(stack.java:22)
at hw9.stack.main(stack.java:45)

View Replies View Related

Why If Statement Isn't Working Correctly

Apr 23, 2015

I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.

import java.util.Scanner;
public class InventorySystem {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int count=0;
int inputEntered=0;
int numberOfItems=0;
double cost=0.00;
String item;
String description;
 
[code]...

View Replies View Related

How To Read A File Correctly

Feb 13, 2014

So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I

Java Code: System.out.println("--Reading text file--");
File file = getFile(c,fileName) // Returns a File object.
System.out.println(file); // Shows me the file is looking correct. Displays contents to console.
BufferedReader br = new BufferedReader(new FileReader(file));
System.out.println("BUFFERED");
while((line = br.readLine()) != null) {
try {
// Do Logic
}
catch(Exception ex){
ex.printStackTrace();
}
br.close(); mh_sh_highlight_all('java');

View Replies View Related

If Else / Switch Not Outputting Correctly

Jan 27, 2014

Trying to learn switch statements. Can't figure out what I am doing wrong.

java Code:

import java.util.Scanner;
public class Ok1 {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

[code]...
When I run, it makes me enter letter = null and it wont output correctly.

View Replies View Related

Write Correctly Border And Gravity

Sep 27, 2014

I want to write simple game. Why if I press button UP and RIGHT it not move diogonally, may be it have special code. And how I need to write correctly border and gravity?

public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Stickman");
Ground ground = new Ground();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(710, 480);

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved