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

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 < ...