Swimming Pool Calculator
I have to write a program to calculate the volume of a swimming pool. The assignment is as follows:
This Swimming Pool Calculator is one that is very simple to use. As you can see, it is a user interface that will allow the user to enter the desired length, width, and average depth of a pool and the program will calculate the volume of that pool based on the entered information. This information is then stored in a file that can be viewed. The interface contains four text boxes for the user to enter information along with a calculate and an exit button.
I've tried several different ways of writing the program and all always come up with errors. =(
View Answers
April 6, 2010 at 12:18 PM
Hi Friend,
Try the following code:
import java.io.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;
public class PoolVolume {
private JFrame mainFrame;
private JButton calcButton, exitButton;
private JTextField length, width, depth, volume;
private JLabel lengthLabel, widthLabel, depthLabel, volumeLabel;
public PoolVolume() {
mainFrame = new JFrame("Swimming Pool Volume Calculator");
calcButton = new JButton("Calculate volume");
exitButton = new JButton("Exit");
length = new JTextField(5);
width = new JTextField(5);
depth = new JTextField(5);
volume = new JTextField(5);
lengthLabel = new JLabel("Enter the length of the swimming pool: ");
widthLabel = new JLabel("Enter the width of the swimming pool: ");
depthLabel = new JLabel("Enter the depth dept of the swimming pool: ");
volumeLabel = new JLabel("Swimming pool volume: ");
JPanel c=new JPanel(new GridLayout(5,2));
c.add(lengthLabel);
c.add(length);
c.add(widthLabel);
c.add(width);
c.add(depthLabel);
c.add(depth);
c.add(volumeLabel);
c.add(volume);
c.add(calcButton);
c.add(exitButton);
calcButton.setMnemonic('C');
exitButton.setMnemonic('x');
mainFrame.setSize(500,200);
mainFrame.add(c);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
calcButtonHandler chandler =new calcButtonHandler();
calcButton.addActionListener(chandler);
exitButtonHandler ehandler =new exitButtonHandler();
exitButton.addActionListener(ehandler);
FocusHandler fhandler =new FocusHandler();
length.addFocusListener(fhandler);
width.addFocusListener(fhandler);
depth.addFocusListener(fhandler);
volume.addFocusListener(fhandler);
mainFrame.setVisible(true);
}
class calcButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
DecimalFormat num =new DecimalFormat(",###.##");
Double cLength, cWidth, cdepth, cVolume, Total;
String sLength, sWidth, sdepth, sVolume;
sLength =length.getText();
cLength = Double.parseDouble(sLength);
sWidth =width.getText();
cWidth = Double.parseDouble(sWidth);
sdepth =depth.getText();
cdepth = Double.parseDouble(sdepth);
if(e.getSource() == calcButton) {
Total = cLength * cWidth * cdepth;
volume.setText(num.format(Total));
try{
String value=volume.getText();
File file = new File("output.txt");
FileWriter fstream = new FileWriter(file,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("Length= "+sLength+", Width= "+sWidth+", Depth= "+sdepth+" so the volume of Swimming Pool is "+value);
out.newLine();
out.close();
}
catch(Exception ex){}
}
}
}
class exitButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
class FocusHandler implements FocusListener {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
}
}
public static void main(String args[]){
new PoolVolume();
}
}
Thanks
Related Tutorials/Questions & Answers:
swimming pool calculatorswimming pool calculator i'm writing a program to calculate the measurements of a
swimming pool & a hot tub. and then the user can enter... of
swimming pool(ft):");
lengthLabel.setBounds(10, 15, 260, 20
Swimming Pool Calculator - Java Beginners PoolVolume() {
mainFrame = new JFrame("
Swimming Pool Volume
Calculator...
Swimming Pool Calculator I have to write a program to calculate the volume of a
swimming pool. The assignment is as follows:
This
Swimming Pool Advertisements
Swimming Pool Calculator - Java Beginners());
mainFrame = new JFrame("
Swimming Pool Volume
Calculator");
calcButton = new...
Swimming Pool Calculator When I run the program the login window... JTextField(5);
lengthLabel = new JLabel("Enter the length of the
swimming pool Swimming Pool Calculator - Java BeginnersSwimming Pool Calculator Okay, so I tried making the program... );
JLabel lengthLabel = new JLabel( "Enter the length of
swimming pool(ft... of the
swimming pool(ft):" );
widthLabel.setBounds( 10, 60, 260, 20 );
pools.add
POOL a variety of services to customers who own
swimming pools, including cleaning and filling pools.
Create
pool class that calculates the price of a service call... on the amount of time it will take to fill a customer's
pool with water.
Table below
CalculatorCalculator need a simple java program to degin a
CALCULATOR without using ADVANCED JAVA....
Calculator in Java Swing
Java swimming applicationJava
swimming application In deep water associates operate a business that offers a variety of services to customers who own
swimming pools, including cleaning and filling pools. Create
pool class that calculates the price
calculator midletcalculator midlet give me code
calculator midlet in bluetooth application with j2me
Pool ChlorinePool Chlorine *** Deleted by Admin *****
Pool Chlorine
Watson's of Cincinnati is a toy store for adults offering above ground pools,
pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio
Calculator classCalculator class I am a beginner in Eclipse. I have to do a program called
calculator that adds numbers. This is my code so far:
//Margaret
//ICS... class
Calculator extends JFrame implements ActionListener {
JTextField text
Pool ChemicalsPool Chemicals **delted by admin *** a toy store **deleted by admin** offering above ground pools,
pool supplies, Envisions Home Theater electronics, home theater furniture, casual patio furniture, spas & hot tubs etc
ModuleNotFoundError: No module named 'Calculator'ModuleNotFoundError: No module named '
Calculator' Hi,
My Python... '
Calculator'
How to remove the ModuleNotFoundError: No module named '
Calculator' error?
Thanks
Hi,
In your python environment you
calculator - Java Interview Questionscalculator create
calculator by java code Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/example/java/swing/
calculator-in-swing.shtml
Thanks
Program for Calculator - Swing AWTProgram for Calculator write a program for
calculator? Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/example/java/swing/
calculator-in-swing.shtml
Hope that it will be helpful
PHP Tax Calculator - PHPPHP Tax Calculator In my project i required a tax
calculator that can calculate the property tax
simple calculator - Java Beginnerssimple calculator how can i create a simple
calculator using java codes? Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/example/java/swing/
calculator-in-swing.shtml
Thanks
Calculator - JSP-ServletCalculator Dear Deepak Sir,
Calculator program is avilable in Jsp...
calculator program in jsp
function checkValue(){
var msg...;
}
Simple
calculator program in jsp
/>
>
ModuleNotFoundError: No module named 'pool'ModuleNotFoundError: No module named '
pool' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
pool'
How to remove the ModuleNotFoundError: No module named '
pool' error
Scientific Calculator - Java BeginnersScientific Calculator Develop a scientific
calculator using even-driven programming paradigm of Java.?
Thanks in ADVANCE Hi Friend,
Please visit the following link:
http://www.roseindia.net/tutorial/java
matrix calculator - Java Beginnersmatrix calculator hi.....
can you help me in writing source code of matrix
calculator in java...
i know you are the best you can do it!!! show yourself
threads & autorelease poolthreads & autorelease pool How to set autorelease
pool for NSThread method in Objective C?
[NSThread detachNewThreadSelector:@selector... {
NSAutoreleasePool *
pool = [[NSAutoreleasePool alloc] init];
//Do stuff
[
pool release