You may NOT use Java.Swing; you must use JavaFX. You may NOT use Java.Swing; you
ID: 3589474 • Letter: Y
Question
You may NOT use Java.Swing; you must use JavaFX.
You may NOT use Java.Swing; you must use JavaFX.
You may NOT use Java.Swing; you must use JavaFX.
You may NOT use Java.Swing; you must use JavaFX.
Overview
For this assignment you will implement a GUI for an interest table calculator. A video of a calculator that illustrates the functionality you need to implement can be found at Video. Notice that your GUI does not need to look like the video. Actually the one in the video was developed using swing while you need to use JavaFX. About this project:
There are no public/release/secret tests associated with this project.
There is no CVS distribution (more details below).
To submit your project you need to upload a zip file directly to the submit server (No "Submit Project" option is available).
Objectives
Implement Java inner classes
Practice lambda expressions
Practice event-driven programming
Learn some basic Java GUI development
Grading
(40%) GUI
(5%) display area
(5%) principal text field
(5%) rate text field
(5%) years slider
(5%) simple interest button
(5%) compound interest button
(5%) both interest button
(5%) labels (Principal:, Rate(Percentage):, Number of Years:)
(5%) Correct computation of simple interest
(5%) Correct computation of compound interest
(5%) Correct computation of both interests
(25%) Implementation of functionality associated with GUI
(5 pts) One inner class (non-anonymous) to handle some computation (e.g., button event)
(10 pts) One inner class (anonymous) to handle some computation (e.g., button event)
(10 pts) One lambda expressionn to handle some computation (e.g., button event)
(10%) Project implemented using Model-View-Control paradigm
(10%) Style
Clarifications
Code Distribution
For this project we are not providing any code. You need to create an Eclipse project named InterestTable. In that Eclipse project feel free to add any classes/packages you understand you need. To simplify the grading process make sure you have a class named InterestTableGUI.java. This class must have a main method that allow us to run your application.
Specifications
You need to implement a GUI that displays interest tables ranging from 1 up to 25 years. The tables are generated by selecting the appropriate button and based on the principal, rate, and years values provided. One table displays simple interest, the second compound interest, and the third a combination of simple and compound interest. See the provided Video for table format information.
Interest Formulas
The formula to compute simple interest amount is:
simple interest amount = principal + (principal * (rate/100) * years)
The formula to compute compound interest amount is:
Compound Interest Amount = principal * (1 + rate/100)Years
Notice that you do not need to add the principal in this case.
Displaying Currency
To display currency you can use the NumberFormat class (part of java.text) as follows:
String formattedValue = NumberFormat.getCurrencyInstance().format(value);
where value represents the numeric value to format.
Requirements
You may NOT use Swing; you must use JavaFX.
Your GUI should resemble the GUI available in the video.
Make sure you have a class named InterestTableGUI.java. This class must have a main method that allow us to execute your application.
Keep the Model-View-Control model in mind when writing your code. Feel free to add any classes you understand you need. The actual computation of interests should take place in a separate class(es).
No student tests are required for this project.
Your project will be graded by running the main method associated with the InterestTableGUI.java class.
You may not use any tools that generate the GUI code for you.
Interest Table Calculator Principal: $100.00, Rate: 10.0 Year, Simple Interest Amount, Compound Interest Amount 1-$110.00->$110.00 2$120.00$121.00 $130.00>$133.10 4-$140.00->$146.41 5- 150.00- 161.05 Principal: 100 Monthly Payment: 10 Monthly Payment Rate(Percentagel: 10 Number of Years: 1 5 9 13 17 21 25 29 Simplelnterest Compoundinte rest BothinterestsExplanation / Answer
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
import java.text.NumberFormat;
@SuppressWarnings("serial")
public class InterestTableGUI13 extends JPanel
{
private static final int NOYRSMIN = 1;
private static final int NOYRSMAX = 30;
private static final int NOYRSINIT = 5;
private JTextArea mydisplay;
private JScrollPane myscrollPane;
private JPanel mycentralPanel;
private JTextField principalText;
private JTextField percentageText;
private JSlider myslider;
private JPanel mybPanel;
private JButton sIButton;
private JTextField mymonthlyPay;
public InterestTableGUI13(int a, int b)
{
setPreferredSize(new Dimension(a, b));
setLayout(new BorderLayout());
mydisplay = new JTextArea(10, 10);
mydisplay.setLineWrap(true);
mydisplay.setEditable(false);
myscrollPane = new JScrollPane(mydisplay);
add(myscrollPane, BorderLayout.NORTH);
mycentralPanel = new JPanel();
mycentralPanel.add(new JLabel("Principal: "));
principalText = new JTextField(12);
mycentralPanel.add(principalText);
mycentralPanel.add(new JLabel("Monthly Payment: "));
mymonthlyPay = new JTextField(12);
mycentralPanel.add(mymonthlyPay);
mycentralPanel.add(new JLabel("Rate(Percentage): "));
percentageText = new JTextField(5);
mycentralPanel.add(percentageText);
JLabel mysliderLabel = new JLabel("Number of Years: ", JLabel.CENTER);
mysliderLabel.setAlignmentX(CENTER_ALIGNMENT);
myslider = new JSlider(JSlider.HORIZONTAL, NOYRSMIN, NOYRSMAX, NOYRSINIT);
myslider.setMajorTickSpacing(4);
myslider.setMinorTickSpacing(1);
myslider.setPaintTicks(true);
myslider.setPaintLabels(true);
mycentralPanel.add(mysliderLabel);
mycentralPanel.add(myslider);
add(mycentralPanel, BorderLayout.CENTER);
mybPanel = new JPanel();
sIButton = new JButton("SimpleInterest");
JButton cIButton = new JButton("CompoundInterest");
JButton bothButton = new JButton("BothInterests");
mybPanel.add(sIButton);
mybPanel.add(cIButton);
mybPanel.add(bothButton);
add(mybPanel, BorderLayout.SOUTH);
sIButton.addActionListener(new ButtonListener());
cIButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
double myP = getP();
double myR = getR();
int myY = getYrs();
mydisplay.setText(cITable(myP,myR, myY));
}
});
bothButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
double myP = getP();
double myR = getR();
int myY = getYrs();
mydisplay.setText(bothtable(myP, myR, myY));
}
});
}
private double getP()
{
try
{
return Double.parseDouble(principalText.getText());
}
catch(NumberFormatException e)
{
mydisplay.setText("Principal amounts are numbers.");
return 0;
}
}
private double getmyMonthly()
{
try
{
return Double.parseDouble(mymonthlyPay.getText());
}
catch(NumberFormatException ee)
{
mydisplay.setText("Put number!");
return 0;
}
}
private double getR()
{
try
{
return Double.parseDouble(percentageText.getText());
}
catch(NumberFormatException ef)
{
mydisplay.setText("Put number without %");
return 0;
}
}
private int getYrs()
{
return myslider.getValue();
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double myP = getP();
double myR = getR();
int myY = getYrs();
mydisplay.setText(sITable(myP, myR,myY));
}
}
public static void createDisplayGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame myframe = new JFrame("Interest Table Calculator");
myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myframe.setLocation(100, 100);
InterestTableGUI13 mytable = new InterestTableGUI13(675, 300);
myframe.setContentPane(mytable);
myframe.pack();
myframe.setVisible(true);
}
public static double sI(double myP, double rP, double myY)
{
return (myP + myP*(rP/100)*myY);
}
public static String formattedSI(double myP, double rP, double myY)
{
return formattedMoney(sI(myP, rP, myY));
}
public static double cI(double myP, double rP, double myY)
{
return (myP*Math.pow(1+rP/100, myY));
}
public static String formattedCI(double myP, double rP, double myY)
{
return formattedMoney(cI(myP, rP, myY));
}
private static String formattedMoney(double value)
{
NumberFormat myft = NumberFormat.getCurrencyInstance();
return myft.format(value);
}
public static String sITable(double myP, double rP, int myY)
{
String toReturn = "Principal: "+ formattedMoney(myP)+ ", Rate: "+rP;
toReturn+= " Year, Simple Interest Amount";
for(int myrows=1; myrows<= myY; myrows++)
{
toReturn = toReturn +" "+myrows+"-->"+formattedSI(myP, rP, myrows);
}
return toReturn;
}
public static String cITable(double myP, double rP, int myY)
{
String toReturn = "Principal: "+ formattedMoney(myP)+ ", Rate: "+rP;
toReturn+= " Year, Compound Interest Amount";
for(int myrows=1; myrows<= myY; myrows++)
{
toReturn = toReturn +" "+myrows+"-->"+formattedCI(myP, rP, myrows);
}
return toReturn;
}
public static String bothtable(double myP, double rP, int myY)
{
String toReturn = "Principal: "+ formattedMoney(myP)+ ", Rate: "+rP;
toReturn+= " Year, Simple Interest Amount, Compound Interest Amount";
for(int myrows=1; myrows<= myY; myrows++)
{
toReturn += " "+myrows+"-->"+
formattedSI(myP, rP, myrows)+
"-->"+formattedCI(myP, rP, myrows);
}
return toReturn;
}
public static void main(String[] args)
{
createDisplayGUI();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.