Académique Documents
Professionnel Documents
Culture Documents
LAB 6
Student Name
Section
Instructor
Due
Date
Project
TOTAL
Maximum
Points
2 points
2 points
2 points
2 points
1 point
1 point
10
points
Your Score
PROJECT DESCRIPTION
Write and compile a GUI application which computes the amount of a
certificate of deposit on maturity. Use the starter code provided within Figure 1 as
a guideline to develop your GUI.
Information About This Project
This particular program illustrates using the compound interest formula from
finance to
calculate the maturity value of a principal deposit.
For example, consider the following sample data.
amount of deposit: $ 60,000.00
number of years:
10
interest rate:
6.75 ( annual compounding )
To compute the maturity amount for these values, the following expression is
evaluated:
60000.00 ( 1 + 6.75 / 100 ) 10
yielding the amount $ 115,300.21 .
Steps To Complete This Project
STEP 1
When the editor opens, type the program code given in Figure 1 ,
which follows.
Include your name, data and course information in the
heading
portion
of your
program code.
The program
code generates the graphical user interface below.
Page 1 of 12
CSC 156
Student Name
LAB 6
Section
PROJECT ONE
Figure 1
javax.swing.*;
java.awt.*;
java.awt.event.*;
java.text.DecimalFormat;
{
private JLabel amtL, yearL, interestL, valueL;
private JTextField amtTF, yearTF, interestTF, valueTF;
private JButton calculateB, exitB;
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
public Maturity()
{
//create four labels
amtL = new JLabel("Amount deposited : ",
SwingConstants.RIGHT);
yearL = new JLabel("Duration in years : ",
SwingConstants.RIGHT);
interestL = new JLabel("Interest rate : ",
SwingConstants.RIGHT);
valueL = new JLabel("Value on maturity : ",
SwingConstants.RIGHT);
Page 2 of 12
CSC 156
Student Name
LAB 6
Section
}
private class CalculateButtonHandler implements
ActionListener
Page 3 of 12
CSC 156
LAB 6
Student Name
Section
{
double year, amt, interest, value;
DecimalFormat twoDigits = new DecimalFormat("0.00");
amt = Double.parseDouble(amtTF.getText());
year = Double.parseDouble(yearTF.getText());
interest = Double.parseDouble(interestTF.getText());
value = amt * Math.pow((1.0 + (interest / 100.0)), year);
valueTF.setText("" + twoDigits.format(value));
}
}
PROJECT ONE
Figure 1
{
System.exit(0);
}
}
public static void main(String args[])
{
Maturity interestProductObject = new Maturity();
}
}
STEP 2
STEP 3
Run your program using the sample data given in the Information
About This Project section of this lab project.
Take a screen snapshot displaying the input values and the
corresponding
output value. Paste the snapshot in a word processing
document and submit
the hardcopy for credit.
STEP 4
Close your application and return to your Java editor to modify your
program
code.
Include, in your code, a new label field and a new text field to give the
Page 4 of 12
CSC 156
Student Name
LAB 6
Section
user the
ability to enter the compound frequency of the investment. To
understand how
to modify your code for this entry, consider the example
data, given in the
Information About This Project section of this lab
project, when the
compounding frequency is semi - annual ( twice per year
). In this case the
given data would be:
amount of deposit:
number of years:
interest rate:
expression is
$ 60,000.00
10
6.75 ( semi - annual compounding )
and to compute the maturity amount for these values, the following
evaluated:
60000.00 ( 1 + 6.75 / 100 / 2 )
20
Run the modified program with the above sample data and take a
screen
snapshot displaying the input values and the corresponding
output value.
Paste the snapshot in a word processing document and submit the
hardcopy
for credit. Submit your completed program code as well.
PROJECT DESCRIPTION
Write a program that has the capability of generating a depreciation report
based on
given information.
Information About This Project
This particular program illustrates the importance of a business system
application using a graphical user interface.
The type of depreciation used in the report is straight - line or linear
depreciation.
In accounting, the amount D of annual, straight - line depreciation is
computed using the formula:
D =
where the asset cost is the purchase price of the asset, the salvage value is
the expected residual value upon disposal of the asset and the asset life is the
lifetime of the item.
Page 5 of 12
CSC 156
Student Name
LAB 6
Section
STEP 2
Open a new Java file named Depreciation.java . Within the file, write
the
program code which will generate a depreciation report. Sample
depreciation report code is given in Figure 1 , which follows.
When executed, the code shows the GUI application given below.
the
below.
When the user enters an asset cost and presses Enter , a label shows
amount of depreciation, as shown in the sample screen given
PROJECT TWO
Figure 1
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
class Depreciation extends Frame
implements ActionListener, WindowListener
{
Label directions;
TextField cost;
Label value;
Depreciation(String s) {
super(s);
setSize(300,100);
setLayout(new FlowLayout());
addWindowListener(this);
directions = new Label("enter the asset cost: ");
add(directions);
cost = new TextField(5);
Page 6 of 12
CSC 156
LAB 6
Student Name
Section
add(cost);
cost.addActionListener(this);
value = new Label("
");
value.setFont(new Font("Tahoma 12 point bold. ", 20, 20));
add(value);
setVisible(true);
}
public
public
public
public
public
public
public
void
void
void
void
void
void
void
windowClosed(WindowEvent event) { }
windowDeiconified(WindowEvent event) { }
windowIconified(WindowEvent event) { }
windowActivated(WindowEvent event) { }
windowDeactivated(WindowEvent event) { }
windowOpened(WindowEvent event) { }
windowClosing(WindowEvent event) { System.exit(0);
}
public void actionPerformed(ActionEvent event) {
DecimalFormat twoDecimal = new DecimalFormat("0.00");
int c = Integer.parseInt(cost.getText());
double amount = (c 500) / 10;
cost.setText(" ");
value.setText(" amount = $" + twoDecimal.format(amount));
}
}
class TestDepreciation
{ public static void main(String args[])
{ new Depreciation("Depreciation"); }
}
PROJECT TWO
500 and the
The above program code assumes that the asset salvage value is $
asset life is 10 years.
STEP 3
and press
.
label.
Run the application, and enter an asset cost of 5000 in the text field
Enter . The depreciation amount is then displayed in the applications
Close the application and return to the Java code editor.
STEP 4
Modify the deprecation application such that the user will have the
ability to
enter not only the asset cost but the salvage value and
asset life as well. The
input of these three items may be through
JOptionPane Input dialog boxes.
STEP 5
Page 7 of 12
CSC 156
LAB 6
Student Name
Section
Run the modified application and test it with the sample data given
below.
Figure 2
Depreciation Scenario
asset type
computer system
asset cost
salvage value
asset life
$ 5,000.00
$ 300.00
5 years
PROJECT DESCRIPTION
Onto your Java text editor, copy the program code given in Figure 1 , which
follows.
Then run the program and observe the frame object created by the
program code.
Information About This Project
This particular program illustrates an example of using the frame object.
Steps To Complete This Project
STEP 1
Page 8 of 12
CSC 156
Student Name
LAB 6
Section
Open a Java text editor. Open a new Java file and name it as
TestFrame since this is the theme for this project. Click OK to close
the New dialog box. When the Java editor opens, type the program
code given in Figure 1 below. Include your name, data and course
information in the heading portion of your program code.
Figure 1
import java.awt.Frame;
//includes the Frame class
class TestFrame
{
public static void main(String args[])
}//end main
}//end class TestFrame
PROJECT THREE
STEP 2
After you have typed the given program, compile it. If the program
compiles
correctly, run it and you will see a frame appear, as shown
below.
To close the frame click the Console screen and then use the keyboard
shortcut
Page 9 of 12
CSC 156
Student Name
LAB 6
Section
STEP 3
import java.awt.Color;
Locate the following line of code
{
ColorFrame(String s)
super(s);
setBackground(Color.blue);
setSize(250, 100);
setVisible(true); //displays frame on the screen
}
}}//end class ColorFrame
Locate the following block of code in the main() method.
Page 10 of 12
CSC 156
LAB 6
Student Name
Section
Take a screen snapshot of the color frame and submit it for credit.
Close the running application and return to your Java Code editor.
STEP 5
Add a Button
Return to your Java Code editor and modify the application to include
color in the frame.
To do this, add the following import statement to the heading
declarations portion of the code.
import java.awt.Button;
ColorFrame(String s)
Button button;
// declare a button
setVisible(true);
setLocation(400,50);
button = new Button("click to continue");
//creates a button
add(button); //makes button a component
the
After you make these modifications, run your application and observe
button that appears. Refer to the snapshot given below.
PROJECT THREE
Take a screen snapshot of the color frame and submit it for credit.
Close your running frame and return to your Java Code editor and
supplement your code to give the user the ability to exit the application
when the button is clicked.
Page 11 of 12
CSC 156
Student Name
LAB 6
Section
Page 12 of 12