This project calls for the modification of the DollarFormat clas.pdf
Business App Programming Course Project
1. Business App Programming Course Project – Carmen Lampkin
CarmenLampkin
1. Requestfornewapplication
Date of request: 3/29/2014
Name of the requester: Landscape architect
Purpose of the request: Needing a computer programmer, analyst, and
designer to help create a GUI program that
calculates engineering specifications
Title of application: Engineering Specifications Calculator
Descriptionof algorithms: Calculate volume for user by asking for length,
width, and depth of either a pool, spa or hot tub
Notes: 1. Program shouldbe userfriendly
2. Program shouldvalidate input
Approval: Approved
2. ProblemAnalysis
I have beenaskedtojoina teamto helpcreate a program that the landscape architectscanuse
to calculate engineeringspecifications.Ihave beenassignedspecificallytothe pools,spas,and
hot tubssectionof the landscapingteam.Thatbeingsaid,the programI create shouldbe able to
workfor any of these three itemsthatthe architectneedsinformationabout.
3. List andDescriptionsof Requirements
I will needtocreate three classes:apool class,spa class,andhot tub class.These three classes
will be usedtocreate the GUI program forthat specificitem.Thisconsistsof creatingJava
componentssuchas labels,textfields,andbuttonsforthe interface of the program.Thenthe
architectshouldbe able toenterininformationandgetsome type of response afterclicking
certainbuttons.Inorderfor that to happenImust implementeventhandlersintomyprogram.
My programshouldbe user-friendlysoeveryone onthe landscapingteamcanuse itand
creative whichmeansIneedtoadd some colorto give itstyle.
4. Interface Storyboard/Drawing
Button
Title:
Engineering
calculator
POOL
Enter the height:
Enter the width:
Enter the depth:
Image
of pool
Volume =
Exit
Button
Calculate
Volume
Button
2. 5. DesignFlowchartorPseudocode
Course Project – Java Code
/***********************************************************************
Program Name: EngineeringCalculator.java
Programmer's Name: Carmen Lampkin
Program Description: Program takes the user inputted height, width, and depth
and calculates the volume.
***********************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.*;
public class EngineeringCalculator extends JFrame {
private JLabel enterHeight;
private JLabel enterWidth;
private JLabel enterDepth;
private JLabel volume;
private JLabel currentDate;
private JTextField height;
private JTextField width;
private JTextField depth;
private JTextField volumeResults;
private JButton calVolumeButton;
private JButton resetButton;
private JButton exitButton;
private JTextField dateField;
private JButton setNameButton;
private JTextField nameOfCompany;
public EngineeringCalculator(){
Start
program
Get height
and validate
Get width
and validate
Get depth
and validate
Display
volume
End
program
3. super("Landscape Volume Calculator");
setLayout(new FlowLayout());
JTabbedPane tabbedPane = new JTabbedPane();
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new FlowLayout());
inputPanel.setPreferredSize(new Dimension (400,400));
add(inputPanel);
enterHeight = new JLabel("Enter the pool's height:");
add(enterHeight);
inputPanel.add(enterHeight);
height = new JTextField(10);
add(height);
inputPanel.add(height);
enterWidth = new JLabel("Enter the pool's width:");
add(enterWidth);
inputPanel.add(enterWidth);
width = new JTextField(10);
add(width);
inputPanel.add(width);
enterDepth = new JLabel("Enter the pool's depth:");
add(enterDepth);
inputPanel.add(enterDepth);
depth = new JTextField(10);
add(depth);
inputPanel.add(depth);
volume = new JLabel("Pool's volume =");
add(volume);
inputPanel.add(volume);
volumeResults = new JTextField(10);
volumeResults.setEditable(false);
add(volumeResults);
inputPanel.add(volumeResults);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(5,5,0,0));
buttonPanel.setPreferredSize(new Dimension (200,200));
inputPanel.add(buttonPanel);
tabbedPane.add("Pool", inputPanel);
tabbedPane.setPreferredSize(new Dimension(200,350));
this.add(tabbedPane, FlowLayout.LEFT);
4. JPanel datePanel = new JPanel();
datePanel.setLayout(new FlowLayout());
currentDate = new JLabel("Today's Date:");
datePanel.add(currentDate);
dateField = new JTextField(10);
dateField.setEditable(false);
dateField.setText(now());
datePanel.add(dateField);
JPanel optionsPanel = new JPanel();
inputPanel.setLayout(new FlowLayout());
JLabel companyName = new JLabel("Enter the new company name:");
optionsPanel.add(companyName);
nameOfCompany = new JTextField(10);
optionsPanel.add(nameOfCompany);
tabbedPane.addTab("General", datePanel);
tabbedPane.addTab("Options",optionsPanel);
VolumeButtonListener pressButton = new VolumeButtonListener();
calVolumeButton = new JButton("Calculate Volume");
add(calVolumeButton);
buttonPanel.add(calVolumeButton);
calVolumeButton.addActionListener(pressButton);
calVolumeButton.setMnemonic('C');
ResetButtonListener reset = new ResetButtonListener();
resetButton = new JButton("Reset");
add(resetButton);
resetButton.setEnabled(true);
buttonPanel.add(resetButton);
resetButton.addActionListener(reset);
resetButton.setMnemonic('R');
ExitButtonListener exit = new ExitButtonListener();
exitButton = new JButton("Exit");
add(exitButton);
buttonPanel.add(exitButton);
exitButton.addActionListener(exit);
exitButton.setMnemonic('X');
datePanel.add(exitButton);
5. SetNameButtonListener name = new SetNameButtonListener();
setNameButton = new JButton("Set New Name");
optionsPanel.add(setNameButton);
setNameButton.addActionListener(name);
setNameButton.setMnemonic('S');
optionsPanel.add(exitButton);
}
private class VolumeButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
try{
double userHeight = Double.parseDouble(height.getText());
double userWidth = Double.parseDouble(width.getText());
double userDepth = Double.parseDouble(depth.getText());
double finalVolume = (userHeight * userWidth * userDepth);
volumeResults.setEditable(true);
volumeResults.setText(Double.toString(finalVolume));
} catch (NumberFormatException n) {
JOptionPane.showMessageDialog(null,
"Textboxes must be valid numbers and
cannot be left blank");
}
}
}
public class ResetButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
height.setText(null);
width.setText(null);
depth.setText(null);
volumeResults.setText(null);
}
}
public class ExitButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == exitButton) {
System.exit(DISPOSE_ON_CLOSE);
}
6. }
}
public class SetNameButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
setTitle(nameOfCompany.getText());
}
}
public static final String DateFormat = "hh:mm MM/dd/yyyy";
public static String now(){
Calendar cal = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat(DateFormat);
return format.format(cal.getTime());
}
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
EngineeringCalculator f = new EngineeringCalculator();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 400);
f.setLocation(200, 200);
f.setVisible(true);
}
}
7. User’s Manual for Landscape Volume Calculator
Designed by Carmen Lampkin
There are multiple tabs to this application. Each one has a different purpose.
1st Tab – Pool
Description: This tab allows the user to calculate the volume of a swimming pool. It validates
user input before performing the calculation.
How to Use:
First, enter the height of the pool in the textbox provided. Must be a number. Field cannot
be left blank.
8. Next, enter the width of the pool in the textbox provided. Must be a number. Field cannot
be left blank.
Lastly, enter the depth of the swimming pool in the textbox provided. Must be a number.
Field cannot be left blank.
After these three fields have been filled with the correct information, you can calculate
the volume of the pool by hitting the Calculate Volume button. When this is clicked, the
volume will appear in the space underneath the label that says “Pool’s volume =”.
9. The Reset button is in place to allow the user to start over. It erases anything that is in the
length, width, and depth textboxes. The space that includes the volume also gets cleared.
This is a good way to clear the information and proceed to find the volume of a different
pool.
Note: If at any time you happen to enter a non-numerical character into a field or attempt to
calculate the volume with blank fields, a window will pop up that includes an error message that
states “Text boxes must be valid numbers and cannot be left blank”. Simply hit the OK button or
the exit button in the top right corner to go back to the application and reenter your values.
2nd Tab – General
Description: Displays the current date and time of access to the user.
How to Use:
Not much user interaction is needed here. When this tab is clicked, it will show the user
the date and time that they started the application.
10. 3rd Tab – Options
Description: Allows the user to change the name of the company. This is the text that appears in
the top border of the application.
How to Use:
Enter the new name that you have for the company into the textbox provided.
11. Click on the Set New Name button.
The new name will then replace the name in the top border and remain there as the user
continues to access other tabs in the application.