ali11 -1 Light Poster

                    import java.util.Arrays;
                    import java.util.List;
                    import java.util.Random;

                    class DynamicArrayOfInts {

                        private int[] storage;
                        private int size;
                        private final  int INITIAL_CAPACITY = 8;
                        private final int GROW_FACTOR = 2;

                        public DynamicArrayOfInts() {
                          storage = new int[INITIAL_CAPACITY];
                          size = 0;
                        }

                        private void rangeCheck(int index){
                    if (index < 0 || index >= size)

                                      if(index < 0 || index >= size)
                          throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);

                        }

                        private void ensureCapacity(int size_wanted) {
                          int max_capacity = storage.length;
                          if (size_wanted > max_capacity) {
                            max_capacity = max_capacity * GROW_FACTOR +1;
                            storage = Arrays.copyOf(storage, max_capacity); // increases array size + copy contents
                          }
                        }

                        public int size() {
                          return size;

                        }

                         public boolean equals(Object aThat) { // aThat is a DynamicArrayOfInts object
                    if (aThat==this) {
                        return true;
                    } else {
                           return false;  // added so code would compile
                        }
                    }
                        public boolean equals(List<Integer> list)  { // list is a LinkedList, or ArrayList, etc

                           return false;  // added so code would compile
                        }

                        public int get(int position){
                    rangeCheck(position);
                    return storage [position];

                        }

                        public void set(int index, int value){
                            rangeCheck(index);

                                        storage[index] = value;

                        }

                        public void insertAt(int index, int value) {
                            if (index < 0 || index > size)

                                              throw new IndexOutOfBoundsException("Index: " + index + ", Size: "

                                                         + size);

                                        ensureCapacity(size + 1);

                                        int moveCount = size - index;

                                        if (moveCount > 0)

                                              System.arraycopy(storage, index, storage, index + 1, moveCount);

                                        storage[index] = value;

                                        size++;

                        }

                        public void add(int value) {
                    if (size== storage.length)
                    {
                        ensureCapacity ((size+1)*2);
                        }
                        storage[size]= value;
                        size++;
                    }
                        public ...

ali11 -1 Light Poster

I am receiving this error
markup.c: In function ‘GetPrice’:
markup.c:16:23: error: ‘markup’ undeclared (first use in this function)
markup.c:16:23: note: each undeclared identifier is reported only once for each function it appears in
markup.c:17:1: error: ‘output’ undeclared (first use in this function)

here is my codes

    // File: markup.c

        #include<stdio.h>
        // define the value for constant MARKUP

        #define MARKUP 0.1
        float GetPrice(float finalvalue)
        {
        finalvalue=finalvalue-markup*100;
        output=finalvalue;
        return (float)output;
        }

    int main()
    {
    // declare variables

    char proceed;

    float markupvalue;

    float value;

    float finalvalue; 

    float markup=0.1;
    // ask user if they want to use markup calculator
    printf("Would you like to markup an item? y/n:");
        scanf("%c", &proceed);

        // if yes, proceed to next step
        if(proceed == 'y')
        {

    // ask user what item they want to markup
    printf("please enter item value you would like to markup:");
    scanf("%f", &value);

    // print current of an item
    printf("The value you entered is: %c%.2f\n",'$',value);

    // display current markup rate
    printf("The current markup rate is %.1f%c.\n",markup*100,'%');

    finalvalue=(value-markup*100);
    // final price of an item
    printf("The price for your item after markup is: %c%.2f\n",'$',(float)GetPrice(finalvalue));

    }else
    // display this message if user don't want to use markup calculator
    printf("If you didn't want to markup an item you can leave. \n\n");

    // display end message
     printf("Thank you for using Markup Calculator. \n");
    return 0;
    }

ali11 -1

I m trying to add scanner class to ask the users to type rational no.

ali11 -1

[QUOTE=NormR1;1710338]What will your Main class use the Rational class for?[/QUOTE]
to test the result.

ali11 -1

[QUOTE=NormR1;1710325]What code is in the Main class? Will the Main class be an inner class?
Or is the Main class the class with a main() method that will create instances of the Rational class and call its methods.

There is no need to create a separate class just to hold the main() method that you are using for testing. You can add it directly to the Rational class.[/QUOTE]
i m trying to create main class to ask users enter rational no.

ali11 -1 Light Poster

need help to add main class to test this program.

[CODE]public class Rational
{
private int num;
private int den;

public Rational (  )
{
    num = 0;
    den = 1;
}

public Rational (int a, int B)
{
    num = a;
    den = b;
    simplify ( );
}

private void simplify ( )
{
    int GCD = getGCD (num,den);
    num /= GCD;
    den /= GCD;

}

private int getGCD ( int a, int b )
{
    int dividend = Math.abs (a);
    int divisor = Math.abs (B);
    int rem = 0;

    do
    {
        rem = dividend % divisor;
        if (rem != 0)
        {
            dividend = divisor;
            divisor = rem;
        }
    } while (rem != 0);

    return divisor;
}

public double getValue ( )
{

    return (double) num / den;

}

public String toString ( )
{
    String outString = "";
    if ((num * den) < 0)
        outString += "-";

    outString += (Math.abs (num));

    if (Math.abs (den) != 1)
        outString += ("/" + Math.abs (den));

    return outString;
}

}[/CODE]

ali11 -1

[QUOTE=zeroliken;1709132]I gave a pseudo a while ago
if you don't know about booleans then you can learn it using google then implement it on your code[/QUOTE]
thanks

ali11 -1

[QUOTE=zeroliken;1709125]I just said that you should use the number of bounces as a requirement for stopping the loop

(said that in 3 posts plus this already)

use a boolean like statement[/QUOTE]
how can i do that.

ali11 -1

[QUOTE=zeroliken;1709121]I'm not contradicting you I said the loop should stop once the required number of bounces is met, meaning you can still print "bounce" and will only not print anymore once the condition is met... you can still have the else statement I only said not to use break;[/QUOTE]
i remove break from my codes and run the program.my program keeps running and doesn't stop.nomatter what no i put for "enter the no of bounces".

ali11 -1

[QUOTE=zeroliken;1709115]Thats because you put in a break statement to stop the whole do while loop
Use a different approach in stopping the loop like a boolean[/QUOTE]
but i also want my program to print "bounce".depends on nos of time user want.

ali11 -1

[QUOTE=zeroliken;1709102]So whats the problem with the bounces can you specify your desired output?

also you should have used your previous thread instead of creating a new one[/QUOTE]
i want my program to print the word "bounce".suppose for "enter the no bounces" if i put 5.then everytime the new height is less then zero my program will print "bounce" .after 5th bounce my progrm will stop.

ali11 -1 Light Poster

Hi i m trying to design a program using object oriented approach.everything works perfect for me except the bounces.If the new height is less then 0 then multiply both the height and velocity by -0.5 to simulate the bounce.
[CODE]import java.util.Scanner;
public class Ball11
{
public static void main (String [ ] args)
{
double height = 0;

    int times = 0;

    int speed=0;
    int bounces=0;

    int numOfBounces = 0;
    Scanner scan= new Scanner (System.in);
    System.out.println("Enter the initial velocity of the ball:");
    height=scan.nextInt();

    System.out.println("Enter the no of speed");
    speed=scan.nextInt();

    System.out.println("enter the no of bounces");
    bounces=scan.nextInt();

    System.out.println();

//Allow the user to play the ball as many times as he wants and each time he can decide the initial ball speed and the number of bounces to stop the ball

        do
        {
            times++;
            height =height + speed;

            speed-=32;

            if (height > 0)

                System.out.println ("time = " + times + "   height = " + height + "   speed = " + speed);
            else
            {
                height = (double) (height * (-0.5));
                speed = (int) (speed * (-0.5));
                System.out.println ("bounce!");

                System.out.println ("time = " + times + "   height = " + height + "   speed = " + speed );

                break;
            }
        } while (true);
        bounces++;

}

}[/CODE]

ali11 -1 Light Poster

Re-design the program using the object-oriented approach

  • Allow the user to play the ball as many times as he wants and each time he can decide the initial ball speed and the number of bounces to stop the ball
    here is what i did before.
    [CODE]import java.util.Scanner;
    public class Ball
    {
    public static void main (String [ ] args)
    {
    double height = 0;

    int times = 0;
    int x=0;

    int numOfBounces = 0;
    Scanner scan= new Scanner (System.in);
    System.out.println("Enter the initial velocity of the ball:");
    x=scan.nextInt();
    System.out.println();

    System.out.println ("time = " + times + " height = " + height);

    do
    {
    do
    {
    times++;
    height =height + x;
    x-=32;

    if (height > 0)

    System.out.println ("time = " + times + " height = " + height);
    else
    {
    height = (double) (height (-0.5));
    x = (int) (x
    (-0.5));

    System.out.println ("bounce!");
    System.out.println ("time = " + times + " height = " + height );

    break;
    }
    } while (true);
    numOfBounces++;

    } while (numOfBounces < 5);

    System.exit (0);

    }
    }[/CODE]

hiddepolen commented: Homework question -1

ali11 -1 Light Poster

Note: C:\Users\Hamza\Desktop\Graph.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Tool completed successfully

[CODE]import java.io.InputStream;
import java.net.URL;

import java.util.;
import java.awt.
;
import java.applet.Applet;
class Node {
double x;
double y;
int lane;
int road;
double dx;
double dy;
String lbl;
int carW;
int carL;
double carWaiting;
}

class ChangeLight implements Runnable {
int signal;
int pauss, redpauss, greenpauss;
Thread lighter;

ChangeLight(){
   signal=1;
   redpauss=6000;
   greenpauss=6000;

}

public void run() {
signal=1;
while (true) {
if (signal==1){
signal=0;
pauss=greenpauss;
}
else {
signal=1;
pauss=redpauss;
}
try {
Thread.sleep(pauss);
} catch (InterruptedException e) {
break;
}
}
}
public void start() {
lighter = new Thread(this);
lighter.start();
}
public void stop() {
lighter.stop();
}
}

class CalFlow implements Runnable {
int carnum, count;
double carwt;
int pauss;
double time0, time1, timelap;
double carflow[] = new double[40];

Thread flow;

CalFlow(){
  carnum=0;
  carwt=0;
  pauss=2000;
  time0=0;
  time1=0;
  for (int k=0; k<40; k++)
     carflow[k]=0;
  count=0;

}

public void run() {
while (true) {
             time1= System.currentTimeMillis();
             timelap=time1-time0;
             if (timelap >50)
     carflow[count]= ((double)(carnum)/timelap)*1000;
             count=(count+1)%40;

    try {
    Thread.sleep(pauss);
    } catch (InterruptedException e) {
    break;
    }
}
}
public void start() {
flow = new Thread(this);
flow.start();
}
public void stop() {
flow.stop();
}

}

class GraphPanel extends Applet implements Runnable {
Graph graph;
int nnodes;
int lghtOrStp;
Node nodes[] = new Node[100];
ChangeLight light[] = new ChangeLight[5];
CalFlow carpermin[] = new CalFlow[5];
Thread relaxer, flow;
int brgflag[] = new int[5];
double speed=10;
int carwidth=6, carlength=9;
int xpos[]= new int[5];
int ypos=200;
int brgright[] = new int[5]; ...

ali11 -1 Light Poster

can somebody help. i m getting following errors. i m creating postfix calc
C:\Users\Hamza\Pictures\CalcGUIPanel.java:204: int cannot be dereferenced
Integer arg2=resultValue.pop();
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:205: int cannot be dereferenced
resultValue.push(resultValue.pop()+arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:205: operator + cannot be applied to ,java.lang.Integer
resultValue.push(resultValue.pop()+arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:205: int cannot be dereferenced
resultValue.push(resultValue.pop()+arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:211: int cannot be dereferenced
Integer arg2=resultValue.pop();
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:212: int cannot be dereferenced
resultValue.push(resultValue.pop()-arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:212: int cannot be dereferenced
resultValue.push(resultValue.pop()-arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:219: int cannot be dereferenced
Integer arg2=resultValue.pop();
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:220: int cannot be dereferenced
resultValue.push(resultValue.pop()arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:220: int cannot be dereferenced
resultValue.push(resultValue.pop()
arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:227: int cannot be dereferenced
Integer arg2=resultValue.pop();
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:228: int cannot be dereferenced
resultValue.push(resultValue.pop()-arg2);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:228: int cannot be dereferenced
resultValue.push(resultValue.pop()-arg2);
^
13 errors

Tool completed with exit code 1

[CODE]import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;

public class CalcGUIPanel extends JPanel
{

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

Stack cStack=new Stack();

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

JButton clearButton = new JButton("CLEAR");

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = new JPanel(new GridLayout(5, 3));

for ...

ali11 -1 Light Poster

I m new.I am not getting any result for

Number of A
Number of B
Numbers of C
Number of D
number of F
for A,B,C,D,F i always get 0.
[CODE]import java.util.Scanner;
public class ExamScores1
{
public static void main (String[]args)
{
String a;
int count= 0;

    int grade=0;     // you declare grade = 0 here
    int A=0;
    int B=0;
    int C=0;
    int D=0;
    int F=0;

    Scanner scan = new Scanner (System.in);
    System.out.println("Enter your exam grades");

    a=scan.nextLine();
    int len=a.length ();

    for (int i=0; i< len; i++)
    {
        if (a.charAt (i) ==' '){
            count--;
        }else {
            count++;

        }
    }

// grade is still == 0 here

    if (grade > 90 && grade <= 100) {
        grade= 'A';
        A=A+1;
        count++;
    } else if (grade > 80 && grade <= 89) {
        grade= 'B';
        B=B+1;
        count++;

    } else if (grade > 70 && grade <= 79) {
        grade= 'C';
        C=C+1;
        count++;

    } else if (grade > 60 && grade <= 69) {
        grade= 'D';
        D=D+1;
        count++;
    } else if (grade> 0 && grade <= 59) {
        grade= 'F';
        F=F+1;
        count++;
    }
    System.out.println("total no of grades=" + count);
    System.out.println("Number of A=" + A);
    System.out.println("Number of B=" + B);
    System.out.println("Number of C=" + C);
    System.out.println("Number of D=" + D);
    System.out.println("Number of F=" + F);
}

}[/CODE]

ali11 -1

[QUOTE=javaNooblet;1691360]Also, you should make your datafields(variables) have more meaningful names so your code is easier to read, as I too learned because I did not used to do it either. And use better english for your output, so it looks better for the user, for example you have:

[CODE]
total no of grades=10
Number of A=2
Number of B=2
Number of C=2
Number of D=2
Number of F=2
[/CODE]

Try something like this for your println:

[CODE]
System.out.println("Total number of each letter grade: " + numberOfGrades);
[/CODE]

Hope all this helped.[/QUOTE]

ok i make changes and here r my codes.
[CODE]import java.util.Scanner;
public class ExamScores
{
public static void main (String[]args)
{
String letterGrade;
double numberOfGrades;
double grade;
//create scanner object
Scanner scan = new Scanner(System.in);
//ask user for input
System.out.println("How many grades do you have to enter?: ");
//reads in the number of grades user wants to enter as double from keyboard
numberOfGrades = scan.nextDouble();
//now since program knows how many grades are being entered it can
//control the input
for(int j = 1; j <= numberOfGrades; j++)
//based off of number of grades the user inputs it will ask
//for that many exam grades
System.out.println("Enter your exam grades: ");
//reads in exam scores as a double from keyboard
grade = scan.nextDouble();
//compares the datafield grade with scores 90-100
if (grade >= 90 && grade <= 100) {
//if 90 >= grade <=100 the letter grade is A
letterGrade = "A";
//if letter grade is A then A which ...

ali11 -1 Light Poster

Hi i m creating simple rpn calculator.I m getting following errors.
C:\Users\Hamza\Pictures\CalcGUIPanel.java:63: array required, but java.lang.String found
cStack.push(buttonOrder[i]);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:213: currentValue is already defined in actionPerformed(java.awt.event.ActionEvent)
BigInteger currentValue = new BigInteger(cStack.pop());
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:215: operator + cannot be applied to java.math.BigInteger,java.math.BigInteger
resultValue += currentValue;
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:223: currentValue is already defined in actionPerformed(java.awt.event.ActionEvent)
BigInteger currentValue = new BigInteger(cStack.pop());
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:225: operator - cannot be applied to java.math.BigInteger,java.math.BigInteger
resultValue -= currentValue;
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:233: currentValue is already defined in actionPerformed(java.awt.event.ActionEvent)
BigInteger currentValue = new BigInteger(cStack.pop());
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:236: operator cannot be applied to java.math.BigInteger,java.math.BigInteger
resultValue
= currentValue;
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:244: currentValue is already defined in actionPerformed(java.awt.event.ActionEvent)
BigInteger currentValue = new BigInteger(cStack.pop());
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:245: operator / cannot be applied to java.math.BigInteger,java.math.BigInteger
resultValue /= currentValue;
^
9 errors

Tool completed with exit code 1
[CODE]import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;
import java.math.BigInteger;

public class CalcGUIPanel extends JPanel
{

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

Stack cStack=new Stack();

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

JButton clearButton = new JButton("CLEAR");

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = ...

ali11 -1

[QUOTE=stultuske;1691146]ehm .. yeah, pretty normal.
you instantiate your variable 'grade' to 0, never change the value yet you do test on this value.
no matter how many times you run it, grade will always be 0[/QUOTE]
so how i change change the grade value.

ali11 -1 Light Poster

Hi i am looking for following output.I am just getting 0 for a,b,c,d,f.
total no of grades
Number of A's
Number of B
Numbers of C
Number of D
number of F

[CODE]import java.util.Scanner;
public class ExamScores
{
public static void main (String[]args)
{
String a;
int count= 0;

    int grade=0;
    int A=0;
    int B=0;
    int C=0;
    int D=0;
    int F=0;

Scanner scan = new Scanner (System.in);
System.out.println("Enter your exam grades");

a=scan.nextLine();
int len=a.length ();

for (int i=0; i< len; i++)
{
    if (a.charAt (i) ==' '){
    count--;
}else {
    count++;

}
}

if (grade > 90 && grade <= 100) {
grade= 'A';
A=A+1;

count++;

} else if (grade > 80 && grade <= 89) {
grade= 'B';
B=B+1;
count++;

} else if (grade > 70 && grade <= 79) {
grade= 'C';
C=C+1;
count++;

} else if (grade > 60 && grade <= 69) {
grade= 'D';
D=D+1;
count++;
} else if (grade> 0 && grade <= 59) {
grade= 'F';
F=F+1;
count++;
}
System.out.println("total no of grades=" + count);
System.out.println("Number of A=" + A);
System.out.println("Number of B=" + B);
System.out.println("Number of C=" + C);
System.out.println("Number of D=" + D);
System.out.println("Number of F=" + F);
}
}[/CODE]

ali11 -1

so these are my cods.
[CODE]import java.util.Scanner;
public class ExamScores
{
public static void main (String[]args)
{
String a;
int count= 0;
int grade=0;
char A,B,C,D,F;

Scanner scan = new Scanner (System.in);
System.out.println("Enter your exam grades");

a=scan.nextLine();
int len=a.length ();

for (int i=0; i< len; i++)
{
    if (a.charAt (i) ==' '){
    count--;
}else {
    count++;

}
}

if (grade > 90 && grade <= 100) {
grade= 'A';
count++;
} else if (grade > 80 && grade <= 89) {
grade= 'B';

} else if (grade > 70 && grade <= 79) {
grade= 'C';
count++;

} else if (grade > 60 && grade <= 69) {
grade= 'D';
count++;
} else if (grade> 0 && grade <= 59) {
grade= 'F';
count++;
}
System.out.println("total no of grades=" + count);
System.out.println("Number of A=" + A);
System.out.println("Number of B=" + B);
System.out.println("Number of C=" + C);
System.out.println("Number of D=" + D);
System.out.println("Number of F=" + F);
}
}[/CODE]

ali11 -1 Light Poster

Hi i am looking for following output.I am not getting these.
System.out.println(total no of grades)
Number of A's
Number of B
Numbers of C
Number of D
number of F
[CODE]import java.util.Scanner;
public class ExamScores
{
public static void main (String[]args)
{
String a;
int count= 0;
String word;
int grade=0;

Scanner scan = new Scanner (System.in);
System.out.println("Enter your exam grades");

a=scan.nextLine();
int len=a.length ();

for (int i=0; i< len; i++)
{
    if (a.charAt (i) ==' '){
    count--;
}else {
    count++;

System.out.println(count);

}
}

if (grade > 90 && grade <= 100) {
grade= 'A';
} else if (grade > 80 && grade <= 89) {
grade= 'B';

} else if (grade > 70 && grade <= 79) {
grade= 'C';

} else if (grade > 60 && grade <= 69) {
grade= 'D';

} else if (grade> 0 && grade <= 59) {
grade= 'F';
}
System.out.print( grade);
}
}[/CODE]

ali11 -1

[QUOTE=NormR1;1687873]The compiler can not find the definition for the variable shown in the error message.
You need to look at each error message, get the symbol that was not found, go into your code and find where it is defined. If it is not defined, you need to define it.
If it is defined make sure its definition is in scope with the place that you are trying to use it.

For classes that are not found, like BigInteger, you need to add an import statement for the package that the class is in to tell the compiler where to find the definition for the class. Go to the API doc, find the page for the class and look at the top of the page to see what package the class is in.

You should learn to compile the program more often to find each error as you make it instead of waiting to do your compile and then having too many errors all at one time.[/quote]

I just update my codes.
[CODE]import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;
import java.math.BigInteger;

public class CalcGUIPanel extends JPanel
{

//=============================================== instance variables

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

Stack cStack=new Stack();

public CalcGUIPanel()
{

//--- Display ...

ali11 -1

[QUOTE=mKorbel;1687804]you have to check your curly brackets[/QUOTE]
these are the errors I am getting.
C:\Users\Hamza\Pictures\CalcGUIPanel.java:43: cannot find symbol
symbol : variable BIGGER_FONT
location: class CalcGUIPanel
clearButton.setFont(BIGGER_FONT);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:63: array required, but java.lang.String found
cStack.push(buttonOrder[i]);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:80: cannot find symbol
symbol : variable BIGGER_FONT
location: class CalcGUIPanel
b.setFont(BIGGER_FONT);
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:113: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("1");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:114: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("2");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:115: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("3");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:116: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("4");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:117: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("5");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:118: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("6");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:119: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("7");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:120: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("8");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:121: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("9");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:122: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("0");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:123: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("+");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:124: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("-");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:125: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("*");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:126: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("/");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:127: cannot find symbol
symbol : variable c
location: class CalcGUIPanel
c.push("enter");
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:130: cannot find symbol
symbol : variable ...

ali11 -1

what do you want to fix, I miss there question

these are the errors i am getting. I am not sure whats the reason.

\Users\Hamza\Pictures\CalcGUIPanel.java:252: 'catch' without 'try'
 } catch (NumberFormatException ex) {
   ^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:252: ')' expected
 } catch (NumberFormatException ex) {
                               ^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:252: not a statement
 } catch (NumberFormatException ex) {
         ^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:252: ';' expected
 } catch (NumberFormatException ex) {
                                  ^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:193: 'try' without 'catch' or 'finally'
try {
^
C:\Users\Hamza\Pictures\CalcGUIPanel.java:310: reached end of file while parsing
}
 ^
6 errors

ali11 -1 Light Poster

can someone help me to fix my codes.I am receving some errors.This is my first time i am using stack in GUI.

[CODE]import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;

public class CalcGUIPanel extends JPanel
{

//=============================================== instance variables

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

Stack cStack=new Stack();

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

JButton clearButton = new JButton("CLEAR");

clearButton.setFont(BIGGER_FONT);

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = new JPanel(new GridLayout(5, 3));

for (int i = 0; i < buttonOrder.length(); i++) {
{
cStack.push(buttonOrder[i]);
}

String keyTop = buttonOrder.substring(i, i+1);

if (keyTop.equals(" ")) {

buttonPanel.add(new JLabel(""));

} else {

JButton b = new JButton(keyTop);

b.addActionListener(numListener);

b.setFont(BIGGER_FONT);

buttonPanel.add(b);

}

}

//--- One ActionListener to use for all operator buttons.

ActionListener opListener = new OpListener();

//--- Create panel with gridlayout to hold operator buttons.

// Use array of button names to create buttons in a loop.

JPanel opPanel = new JPanel(new GridLayout(5, 1));

String[] opOrder = {"+", "-", "*", "/", "enter"};

for (int i = 0; i < ...

ali11 -1 Light Poster

First i create simple claculator.but now I am trying to change it to RPN calculator by using stack.Can some one help me because I don't know alot about stack.here is my codes so far.

[CODE] import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;

public class CalcGUIPanel extends JPanel
{

private Stack s = new Stack();
//=============================================== instance variables

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

//========================================= static (class) variables

private static final Font BIGGER_FONT =

new Font("monspaced", Font.PLAIN, 20);

//====================================================== constructor

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

//--- Clear button

JButton clearButton = new JButton("CLEAR");

clearButton.setFont(BIGGER_FONT);

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = new JPanel(new GridLayout(5, 3));

for (int i = 0; i < buttonOrder.length(); i++) {

String keyTop = buttonOrder.substring(i, i+1);

if (keyTop.equals(" ")) {

buttonPanel.add(new JLabel(""));

} else {

JButton b = new JButton(keyTop);

b.addActionListener(numListener);
s.push("0");
s.push("1");
s.push("2");
s.push("3");
s.push("4");
s.push("5");
s.push("6");
s.push("7");
s.push("8");
s.push("9");

b.setFont(BIGGER_FONT);

buttonPanel.add(b);

}

}

//--- One ActionListener to use for all operator buttons.

ActionListener opListener = new OpListener();

//--- ...

ali11 -1

[QUOTE=adarshcu;1684972]It would be nice if your code is enclosed by code tags. Its not at all readable.[/QUOTE]
sorry i forgot> I just fix it.

ali11 -1

First i create simple claculator.but now I am trying to change it to RPN calculator by using stack.Can some one help me((especially where to use pop method) because I don't know alot about stack.here is my codes so far.
[CODE]import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;

public class CalcGUIPanel extends JPanel
{

Stack s=new Stack();

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

//========================================= static (class) variables

private static final Font BIGGER_FONT =

new Font("monspaced", Font.PLAIN, 20);

//====================================================== constructor

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

//--- Clear button

JButton clearButton = new JButton("CLEAR");

clearButton.setFont(BIGGER_FONT);

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = new JPanel(new GridLayout(5, 3));

for (int i = 0; i < buttonOrder.length(); i++) {

String keyTop = buttonOrder.substring(i, i+1);

if (keyTop.equals(" ")) {

buttonPanel.add(new JLabel(""));

} else {

JButton b = new JButton(keyTop);

b.addActionListener(numListener);
s.push("0");
s.push("1");
s.push("2");
s.push("3");
s.push("4");
s.push("5");
s.push("6");
s.push("7");
s.push("8");
s.push("9");

b.setFont(BIGGER_FONT);

buttonPanel.add(B);

}

}

//--- One ActionListener to use for all operator buttons.

ActionListener opListener = new OpListener();

//--- Create panel with gridlayout to hold ...

ali11 -1 Light Poster

First i create simple claculator.but now I am trying to change it to RPN calculator by using stack.Can some one help me((especially where to use pop method) because I don't know alot about stack.here is my codes so far.
import java.util.Stack;
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;
import java.util.Scanner;

public class CalcGUIPanel extends JPanel
{

Stack s=new Stack();

//--- Component referenced during execution

private JTextField displayField; // display result / input.

//--- Variables representing state of the calculator

private boolean startNumber = true; // true: num key next

private int resultValue = 0; // result so far

private String previousOp = "="; // previous operation

//========================================= static (class) variables

private static final Font BIGGER_FONT =

new Font("monspaced", Font.PLAIN, 20);

//====================================================== constructor

public CalcGUIPanel()
{

//--- Display field

displayField = new JTextField();

//--- Clear button

JButton clearButton = new JButton("CLEAR");

clearButton.setFont(BIGGER_FONT);

clearButton.addActionListener(new ClearListener());

//--- One listener for all numeric keys.

ActionListener numListener = new NumListener();

//--- Layout numeric keys in a grid. Generate the buttons

// in a loop from the chars in a string.

String buttonOrder = "789456123 0 ";

JPanel buttonPanel = new JPanel(new GridLayout(5, 3));

for (int i = 0; i < buttonOrder.length(); i++) {

String keyTop = buttonOrder.substring(i, i+1);

if (keyTop.equals(" ")) {

buttonPanel.add(new JLabel(""));

} else {

JButton b = new JButton(keyTop);

b.addActionListener(numListener);
s.push("0");
s.push("1");
s.push("2");
s.push("3");
s.push("4");
s.push("5");
s.push("6");
s.push("7");
s.push("8");
s.push("9");

b.setFont(BIGGER_FONT);

buttonPanel.add(B);

}

}

//--- One ActionListener to use for all operator buttons.

ActionListener opListener = new OpListener();

//--- Create panel ...