aspose file tools*
The moose likes Beginning Java and the fly likes Still thinking its simple? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Still thinking its simple?

Samuel Robert
Greenhorn

Joined: Dec 02, 2005
Posts: 4
SORRY TO TAKE SO LONG TO REPLY. i believe that it wasthe member marc who said that i was not being specific enough, well i have been trying to get the code to a level that one might understand what i am trying to do exactly and i have attached it to this message.

As for the initial seperate class that i was querying about i still have no idea and believe that it is even worse now than when i first mailed if you could just have a look, any help would be much appreciated and very welcome.

In this seperate class what i am trying to do is a calculation where thae cost is deducted untill the cost is paid.
Ah! sounds so simple, although can be a major bummer when your in the elimentry stages of java programming.

Thanks to all who reply.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class CarPark extends JFrame implements ActionListener

{
JButton tenP, twentyP, fiftyP, onePound, twoPounds,//declaring all East buttons.
less1, oneTwo, twoThree, threeFour, overFour;//declaring all West buttons.
JLabel messLabel = new JLabel("Amount to pay: ");//Message label being created.
JTextField message = new JTextField(10);//Text field is being created with its character limit [10].
double amount = 0;
DecimalFormat pounds = new DecimalFormat("�0.00");

public static void main(String[] args)
{
CarPark c = new CarPark();
c.setTitle("Car park payment simulator");
c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setSize(500, 200);
c.setVisible(true);
}


CarPark() {
setLayout(new BorderLayout());
tenP = new JButton("10p");//creating a button and showing its caption.
tenP.setEnabled(false);
tenP.addActionListener(this);
twentyP = new JButton("20p");
twentyP.setEnabled(false);
twentyP.addActionListener(this);
fiftyP = new JButton("50p");
fiftyP. setEnabled(false);
fiftyP.addActionListener(this);
onePound = new JButton("�1");
onePound.setEnabled(false);
onePound.addActionListener(this);
twoPounds = new JButton("�2");
twoPounds.setEnabled(false);
twoPounds.addActionListener(this);

less1 = new JButton("Up to 1 hr");
less1.addActionListener(this);
oneTwo = new JButton("1 to 2 hr");
oneTwo.addActionListener(this);
twoThree = new JButton("2 to 3 hr");
twoThree.addActionListener(this);
threeFour = new JButton("3 to 4 hr");
threeFour.addActionListener(this);
overFour = new JButton("Over 4 hr");
overFour.addActionListener(this);

JPanel leftSide = new JPanel();
leftSide.setLayout(new GridLayout(5,1));
leftSide.add(tenP);
leftSide.add(twentyP);
leftSide.add(fiftyP);
leftSide.add(onePound);
leftSide.add(twoPounds);
add("West", leftSide);//This labels our left side West.

JPanel rightSide = new JPanel();
rightSide.setLayout(new GridLayout(5, 1));
rightSide.add(less1);
rightSide.add(oneTwo);
rightSide.add(twoThree);
rightSide.add(threeFour);
rightSide.add(overFour);
add("East", rightSide);//This labels our right side East.

JPanel middle = new JPanel();
middle.setLayout(new FlowLayout());
middle.add(messLabel);
message.setEditable(false);//This states that the message positioned in the center can not be editted.
middle.add(message);
add("Center", middle);//This labels the middle Center.
// add extra code to the constructor
}

public void actionPerformed(ActionEvent e)
{
// add your code here
if(e.getSource()== oneTwo)
{
oneTwo.setEnabled(false);
less1.setEnabled(false);
twoThree.setEnabled(false);
threeFour.setEnabled(false);
overFour.setEnabled(false);
message.setText("�2.00");
}



if (e.getSource()== less1)
{
oneTwo.setEnabled(false);
less1.setEnabled(false);
twoThree.setEnabled(false);
threeFour.setEnabled(false);
overFour.setEnabled(false);
tenP.setEnabled(true);
twentyP.setEnabled(true);
fiftyP.setEnabled(true);
onePound.setEnabled(true);
twoPounds.setEnabled(true);
message.setText("�1.00");
}
if (e.getSource()== twoThree)
{
oneTwo.setEnabled(false);
less1.setEnabled(false);
twoThree.setEnabled(false);
threeFour.setEnabled(false);
overFour.setEnabled(false);
tenP.setEnabled(true);
twentyP.setEnabled(true);
fiftyP.setEnabled(true);
onePound.setEnabled(true);
twoPounds.setEnabled(true);
message.setText("�3.50");
}
if (e.getSource() == threeFour)
{
oneTwo.setEnabled(false);
less1.setEnabled(false);
twoThree.setEnabled(false);
threeFour.setEnabled(false);
overFour.setEnabled(false);
tenP.setEnabled(true);
twentyP.setEnabled(true);
fiftyP.setEnabled(true);
onePound.setEnabled(true);
twoPounds.setEnabled(true);
message.setText("�5.00");
}

if (e.getSource() == overFour)
{
oneTwo.setEnabled(false);
less1.setEnabled(false);
twoThree.setEnabled(false);
threeFour.setEnabled(false);
overFour.setEnabled(false);
tenP.setEnabled(true);
twentyP.setEnabled(true);
fiftyP.setEnabled(true);
onePound.setEnabled(true);
twoPounds.setEnabled(true);
message.setText("�6.00");
}
}
}

This is apparently the seperate class for the calculation a hurdle which seems to big to scale.???


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Calculation
{
public static int calculate(int amount)
{
double tenpence = Double.parseDouble(tenP);
double twentypence = Double.parseDouble(twentyP);
double fiftypence = Double.parseDouble(fiftyP);
double onepound = Double.parseDouble(onePound);
double twopound = Double.parseDouble(twoPounds);
int amount = 500
tenpence = (10);
twentypence = (20);
fiftypence = (50);
onepound = (100);
twopound = (200);
int total = amount - fiftypence;
return total;

}
}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

This is a duplicate post. Please continue this discussion in its original thread...

http://www.coderanch.com/t/401685/java/java/should-easy


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
Consider Paul's rocket mass heater.
 
subject: Still thinking its simple?