help me Java project
I put problem and my own code in the link
my code is long link : https://codeshare.io/YohNo
Solution
import javax.swing.*;
import java.awt.Font;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Assignment21 {
/**
* @param args the command line arguments
*/
public static JFrame frame;
public static DecimalFormat fmt = new DecimalFormat ("0.00;(0.00)");
public static String message;
public static boolean firstTime = true;
public static boolean firstTime2 = true;
public static CheckingAccount CheckAcc;
public static Transaction newTrans;
public static void main(String[] args) {
// TODO code application logic here
frame = new JFrame ("Transaction Options");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
EOptionsPanel panel = new EOptionsPanel();
frame.getContentPane().add (panel);
frame.pack();
frame.setVisible(true);
}
public static int getTransCode()
{
String codeStr;
int code;
codeStr=JOptionPane.showInputDialog(" Here are the Transaction
Codes: 1)Checking 2)Depositing 0)Terminate");
code = Integer.parseInt(codeStr);
return code;
}
public static double getTransAmount(){
String tStr;
double tAmount;
tStr = JOptionPane.showInputDialog("Enter the trans amount: ");
tAmount = Double.parseDouble(tStr);
return tAmount;
}
public static double processCheck(double tAmount)
{
CheckAcc.setServiceCharge(0.15);
newTrans = new Transaction(CheckAcc.getTransCount(),3,0.15);
CheckAcc.addTrans(newTrans);
message += " Transaction : Check in Amount of $" + fmt.format(tAmount) +
" Current Balance : $ " + fmt.format(CheckAcc.getBalance()) +
" Service Charge : Check --- charge: $0.15";
if(CheckAcc.getBalance()<500 && firstTime2)
{
CheckAcc.setServiceCharge(5.00);
newTrans = new Transaction(CheckAcc.getTransCount(),3,5.00);
CheckAcc.addTrans(newTrans);
firstTime2=false;
message += " Service Charge : Balance under $500 -- Charge: $5.00";
}
if(CheckAcc.getBalance()<0)
{
CheckAcc.setServiceCharge(10.00);
newTrans = new Transaction(CheckAcc.getTransCount(),3,10.00);
CheckAcc.addTrans(newTrans);
message += " Service Charge : Overdfart Balance --- Charge: $10.00";
}
message += " Total ServiceCharge : $ " + fmt.format(CheckAcc.getServiceCharge());
JOptionPane.showMessageDialog(null, message);
return 0;
}
public static double processDeposit(double tAmount)
{
CheckAcc.setServiceCharge(0.10);
newTrans = new Transaction(CheckAcc.getTransCount(),3,0.10);
CheckAcc.addTrans(newTrans);
message += " Transaction : Deposit in Amount of $" + fmt.format(tAmount) +
" Current Balance : $ " + fmt.format(CheckAcc.getBalance()) +
" Service Charge : Check --- charge: $0.10"+
" Total ServiceCharge : $ " + fmt.format(CheckAcc.getServiceCharge());
JOptionPane.showMessageDialog(null, message);
return 0;
}
public static void inputTransactions()
{
// define local variables
String initialStr;
double initial, tAmount, check, deposit, amount=0;
int code, number=0, id=0;
// get initial balance from the user
if(firstTime)
{
initialStr = JOptionPane.showInputDialog ("Please enter the initial balance: ");
initial = Double.parseDouble (initialStr);
/*
instantiate CheckingAccount object
to keep track of account information
*/
CheckAcc = new CheckingAccount (initial);
firstTime=false;
}
newTrans = new Transaction (number, id, amount);
frame.setVisible(false);
//Loop continues transactions until trans code = 0
do
{
message = "";
code = getTransCode();
if (code != 0) //initially checks that trans code != 0
{
tAmount = getTransAmount();
CheckAcc.setBalance(tAmount, code);
//creating a new Transaction object
newTrans = new Transaction (CheckAcc.getTransCount(), code, tAmount);
CheckAcc.addTrans(newTrans);//inputs the new object in the array
if (CheckAcc.getBalance() < 50)
message = "WARNING: Balance below $50";
if (code == 1)
{
check = processCheck(tAmount);
}
if (code == 2)
{
deposit = processDeposit(tAmount);
}
}
}
while (code != 0);
// When loop ends show final balance to user.
message += "*****************" + " Transaction End"
+ " *****************" + " Current Balance: " + fmt.format(CheckAcc.getBalance())
+ " Total Service Charges: " + fmt.format(CheckAcc.getServiceCharge())
+ " Final Balance: " + fmt.format(CheckAcc.getFinal());
JOptionPane.showMessageDialog(null, message);
frame.setVisible(true);
}
public static void listTransactions()
{
JTextArea text = new JTextArea();
String message = "";
int num;
text.setOpaque(false);
text.setFont(new Font("Monospaced", Font.PLAIN, 14) );
text.setBorder(null);
message+="All Transactions  ";
message+="Number Type Amount($)  ";
for ( num=0; num < CheckAcc.getTransCount(); num++)
{
String word = "";
newTrans = CheckAcc.getTrans(num);
System.out.println(newTrans.getTransId());
//Case switch to convert transID to a trans type (string)
switch (newTrans.getTransId())
{
case 1: word = "Check ";
break;
case 2: word = "Deposit ";
break;
case 3: word = "Service Charge";
}
message += String.format("%3d %10s %10s  ",
newTrans.getTransNumber(), word, fmt.format(newTrans.getTransAmount()));
}
text.setText(message);
JOptionPane.showMessageDialog(null, text);
}
public static void listChecks()
{
JTextArea text = new JTextArea();
String message = "";
int num;
text.setOpaque(false);
text.setFont(new Font("Monospaced", Font.PLAIN, 14) );
text.setBorder(null);
message+="Checks Cashed  ";
message+="Number Amount($)  ";
for ( num=0; num < CheckAcc.getTransCount(); num++)
{
newTrans = CheckAcc.getTrans(num);
if (newTrans.getTransId() == 1)
{
message += String.format("%3d %10s  ",
newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount()));
}
}
text.setText(message);
JOptionPane.showMessageDialog(null, text);
}
public static void listDeposits()
{
JTextArea text = new JTextArea();
String message = "";
int num;
text.setOpaque(false);
text.setFont(new Font("Monospaced", Font.PLAIN, 14) );
text.setBorder(null);
message+="Deposits Made  ";
message+="Number Amount($)  ";
for ( num=0; num < CheckAcc.getTransCount(); num++)
{
newTrans = CheckAcc.getTrans(num);
if (newTrans.getTransId() == 2)
{
message += String.format("%3d %10s  ",
newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount()));
}
}
text.setText(message);
JOptionPane.showMessageDialog(null, text);
}
public static void listService_Charges()
{
JTextArea text = new JTextArea();
String message = "";
int num;
text.setOpaque(false);
text.setFont(new Font("Monospaced", Font.PLAIN, 14) );
text.setBorder(null);
message+="Service Charges  ";
message+="Number Amount($)  ";
for ( num=0; num < CheckAcc.getTransCount(); num++)
{
newTrans = CheckAcc.getTrans(num);
if (newTrans.getTransId() == 3)
{
message += String.format("%3d %10s  ",
newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount()));
}
}
text.setText(message);
JOptionPane.showMessageDialog(null, text);
}
}
//-----------------CheckingAccount.java-------------------------------
package assignment2.pkg1;
import java.util.ArrayList;
public class CheckingAccount
{
private ArrayList transList;// keeps a list of Transaction objects for the account
private int transCount; // the count of Transaction objects and used as the ID for each transaction
private double currentbalance;
private double totalServiceCharge;
private double finalbalance;
public CheckingAccount(double initial)
{
transList = new ArrayList();
currentbalance = initial;
totalServiceCharge = 0;
finalbalance = 0;
}
public double getBalance()
{
return currentbalance;
}
public void setBalance(double tAmount, int transCode)
{
if(transCode == 1)
currentbalance -= tAmount;
else //if(transCode == 2)
currentbalance += tAmount;
}
public double getServiceCharge()
{
return totalServiceCharge;
}
public void setServiceCharge(double currentServiceCharge)
{
totalServiceCharge += currentServiceCharge;
}
public double getFinal()
{
finalbalance = currentbalance - totalServiceCharge;
return finalbalance;
}
public void addTrans(Transaction newTrans)// adds a transaction object to the transList
{
transList.add(newTrans);
transCount ++;
}
public int getTransCount()//returns the current value of transCount;
{
return transCount;
}
public Transaction getTrans(int i)// returns the i-th Transaction object in the list
{
return transList.get(i);
}
}
//---------------------------------EOptionsPanel.java-------------------------------------------
package assignment2.pkg1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import assignment2.pkg1.Assignment21;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
public class EOptionsPanel extends JPanel
{
private JLabel prompt;
private JRadioButton one, two, three, four, five;
//-----------------------------------------------------------------
// Sets up a panel with a label and a set of radio buttons
// that present options to the user.
//-----------------------------------------------------------------
public EOptionsPanel()
{
prompt = new JLabel ("Choose your input option:");
prompt.setFont (new Font ("Courier New", Font.BOLD, 24));
one = new JRadioButton ("Enter A Transaction");
one.setBackground (Color.red);
two = new JRadioButton ("List All Transactions");
two.setBackground (Color.GREEN);
three = new JRadioButton ("List All Checks");
three.setBackground (Color.Blue);
four = new JRadioButton ("List All Deposits");
four.setBackground (Color.yellow);
five= new JRadioButton ("List All Service Charges");
five.setBackground (Color.magenta);
ButtonGroup group = new ButtonGroup();
group.add (one);
group.add (two);
group.add (three);
group.add (four);
group.add (five);
EOptionListener listener = new EOptionListener();
one.addActionListener (listener);
two.addActionListener (listener);
three.addActionListener (listener);
four.addActionListener (listener);
five.addActionListener (listener);
// add the components to the JPanel
add (prompt);
add (one);
add (two);
add (three);
add (four);
add (five);
setBackground (Color.green);
setPreferredSize (new Dimension(400, 140));
}
//*****************************************************************
// Represents the listener for the radio buttons
//*****************************************************************
private class EOptionListener implements ActionListener
{
//--------------------------------------------------------------
// Calls the method to process the option for which radio
// button was pressed.
//--------------------------------------------------------------
public void actionPerformed (ActionEvent event)
{
Object source = event.getSource();
if (source == one)
Assignment21.inputTransactions();
else
if (source == two)
Assignment21.listTransactions();
else
if (source == three)
Assignment21.listChecks();
if (source == four)//list deposits
Assignment21.listDeposits();
if (source == five)
Assignment21.listService_Charges();
}
}
}
//------------------------------Transaction.java-----------------------------------
package assignment2.pkg1;
public class Transaction {
private int transNumber;
private int transId;
private double tAmount;
public Transaction(int number, int id, double amount)
{
transNumber = number;
transId = id;
tAmount = amount;
}
public int getTransNumber()
{
return transNumber;
}
public int getTransId()
{
return transId;
}
public double getTransAmount()
{
return tAmount;
}
}

help me Java projectI put problem and my own code in the linkmy .pdf

  • 1.
    help me Javaproject I put problem and my own code in the link my code is long link : https://codeshare.io/YohNo Solution import javax.swing.*; import java.awt.Font; import javax.swing.JOptionPane; import java.text.DecimalFormat; import java.util.Scanner; public class Assignment21 { /** * @param args the command line arguments */ public static JFrame frame; public static DecimalFormat fmt = new DecimalFormat ("0.00;(0.00)"); public static String message; public static boolean firstTime = true; public static boolean firstTime2 = true; public static CheckingAccount CheckAcc; public static Transaction newTrans; public static void main(String[] args) { // TODO code application logic here frame = new JFrame ("Transaction Options"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); EOptionsPanel panel = new EOptionsPanel(); frame.getContentPane().add (panel); frame.pack(); frame.setVisible(true); } public static int getTransCode() { String codeStr; int code;
  • 2.
    codeStr=JOptionPane.showInputDialog(" Here arethe Transaction Codes: 1)Checking 2)Depositing 0)Terminate"); code = Integer.parseInt(codeStr); return code; } public static double getTransAmount(){ String tStr; double tAmount; tStr = JOptionPane.showInputDialog("Enter the trans amount: "); tAmount = Double.parseDouble(tStr); return tAmount; } public static double processCheck(double tAmount) { CheckAcc.setServiceCharge(0.15); newTrans = new Transaction(CheckAcc.getTransCount(),3,0.15); CheckAcc.addTrans(newTrans); message += " Transaction : Check in Amount of $" + fmt.format(tAmount) + " Current Balance : $ " + fmt.format(CheckAcc.getBalance()) + " Service Charge : Check --- charge: $0.15"; if(CheckAcc.getBalance()<500 && firstTime2) { CheckAcc.setServiceCharge(5.00); newTrans = new Transaction(CheckAcc.getTransCount(),3,5.00); CheckAcc.addTrans(newTrans); firstTime2=false; message += " Service Charge : Balance under $500 -- Charge: $5.00"; } if(CheckAcc.getBalance()<0) { CheckAcc.setServiceCharge(10.00); newTrans = new Transaction(CheckAcc.getTransCount(),3,10.00); CheckAcc.addTrans(newTrans);
  • 3.
    message += "Service Charge : Overdfart Balance --- Charge: $10.00"; } message += " Total ServiceCharge : $ " + fmt.format(CheckAcc.getServiceCharge()); JOptionPane.showMessageDialog(null, message); return 0; } public static double processDeposit(double tAmount) { CheckAcc.setServiceCharge(0.10); newTrans = new Transaction(CheckAcc.getTransCount(),3,0.10); CheckAcc.addTrans(newTrans); message += " Transaction : Deposit in Amount of $" + fmt.format(tAmount) + " Current Balance : $ " + fmt.format(CheckAcc.getBalance()) + " Service Charge : Check --- charge: $0.10"+ " Total ServiceCharge : $ " + fmt.format(CheckAcc.getServiceCharge()); JOptionPane.showMessageDialog(null, message); return 0; } public static void inputTransactions() { // define local variables String initialStr; double initial, tAmount, check, deposit, amount=0; int code, number=0, id=0; // get initial balance from the user if(firstTime) { initialStr = JOptionPane.showInputDialog ("Please enter the initial balance: "); initial = Double.parseDouble (initialStr); /* instantiate CheckingAccount object to keep track of account information
  • 4.
    */ CheckAcc = newCheckingAccount (initial); firstTime=false; } newTrans = new Transaction (number, id, amount); frame.setVisible(false); //Loop continues transactions until trans code = 0 do { message = ""; code = getTransCode(); if (code != 0) //initially checks that trans code != 0 { tAmount = getTransAmount(); CheckAcc.setBalance(tAmount, code); //creating a new Transaction object newTrans = new Transaction (CheckAcc.getTransCount(), code, tAmount); CheckAcc.addTrans(newTrans);//inputs the new object in the array if (CheckAcc.getBalance() < 50) message = "WARNING: Balance below $50"; if (code == 1) { check = processCheck(tAmount); } if (code == 2) { deposit = processDeposit(tAmount); } } }
  • 5.
    while (code !=0); // When loop ends show final balance to user. message += "*****************" + " Transaction End" + " *****************" + " Current Balance: " + fmt.format(CheckAcc.getBalance()) + " Total Service Charges: " + fmt.format(CheckAcc.getServiceCharge()) + " Final Balance: " + fmt.format(CheckAcc.getFinal()); JOptionPane.showMessageDialog(null, message); frame.setVisible(true); } public static void listTransactions() { JTextArea text = new JTextArea(); String message = ""; int num; text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14) ); text.setBorder(null); message+="All Transactions "; message+="Number Type Amount($) "; for ( num=0; num < CheckAcc.getTransCount(); num++) { String word = ""; newTrans = CheckAcc.getTrans(num); System.out.println(newTrans.getTransId()); //Case switch to convert transID to a trans type (string) switch (newTrans.getTransId()) { case 1: word = "Check "; break; case 2: word = "Deposit "; break; case 3: word = "Service Charge"; }
  • 6.
    message += String.format("%3d%10s %10s ", newTrans.getTransNumber(), word, fmt.format(newTrans.getTransAmount())); } text.setText(message); JOptionPane.showMessageDialog(null, text); } public static void listChecks() { JTextArea text = new JTextArea(); String message = ""; int num; text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14) ); text.setBorder(null); message+="Checks Cashed "; message+="Number Amount($) "; for ( num=0; num < CheckAcc.getTransCount(); num++) { newTrans = CheckAcc.getTrans(num); if (newTrans.getTransId() == 1) { message += String.format("%3d %10s ", newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount())); } } text.setText(message); JOptionPane.showMessageDialog(null, text); } public static void listDeposits() { JTextArea text = new JTextArea(); String message = ""; int num; text.setOpaque(false);
  • 7.
    text.setFont(new Font("Monospaced", Font.PLAIN,14) ); text.setBorder(null); message+="Deposits Made "; message+="Number Amount($) "; for ( num=0; num < CheckAcc.getTransCount(); num++) { newTrans = CheckAcc.getTrans(num); if (newTrans.getTransId() == 2) { message += String.format("%3d %10s ", newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount())); } } text.setText(message); JOptionPane.showMessageDialog(null, text); } public static void listService_Charges() { JTextArea text = new JTextArea(); String message = ""; int num; text.setOpaque(false); text.setFont(new Font("Monospaced", Font.PLAIN, 14) ); text.setBorder(null); message+="Service Charges "; message+="Number Amount($) "; for ( num=0; num < CheckAcc.getTransCount(); num++) { newTrans = CheckAcc.getTrans(num); if (newTrans.getTransId() == 3) { message += String.format("%3d %10s ", newTrans.getTransNumber(), fmt.format(newTrans.getTransAmount())); } } text.setText(message);
  • 8.
    JOptionPane.showMessageDialog(null, text); } } //-----------------CheckingAccount.java------------------------------- package assignment2.pkg1; importjava.util.ArrayList; public class CheckingAccount { private ArrayList transList;// keeps a list of Transaction objects for the account private int transCount; // the count of Transaction objects and used as the ID for each transaction private double currentbalance; private double totalServiceCharge; private double finalbalance; public CheckingAccount(double initial) { transList = new ArrayList(); currentbalance = initial; totalServiceCharge = 0; finalbalance = 0; } public double getBalance() { return currentbalance; } public void setBalance(double tAmount, int transCode) { if(transCode == 1) currentbalance -= tAmount; else //if(transCode == 2) currentbalance += tAmount; } public double getServiceCharge()
  • 9.
    { return totalServiceCharge; } public voidsetServiceCharge(double currentServiceCharge) { totalServiceCharge += currentServiceCharge; } public double getFinal() { finalbalance = currentbalance - totalServiceCharge; return finalbalance; } public void addTrans(Transaction newTrans)// adds a transaction object to the transList { transList.add(newTrans); transCount ++; } public int getTransCount()//returns the current value of transCount; { return transCount; } public Transaction getTrans(int i)// returns the i-th Transaction object in the list { return transList.get(i); } } //---------------------------------EOptionsPanel.java------------------------------------------- package assignment2.pkg1; import javax.swing.*; import java.awt.*;
  • 10.
    import java.awt.event.*; import assignment2.pkg1.Assignment21; importjavax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Color; public class EOptionsPanel extends JPanel { private JLabel prompt; private JRadioButton one, two, three, four, five; //----------------------------------------------------------------- // Sets up a panel with a label and a set of radio buttons // that present options to the user. //----------------------------------------------------------------- public EOptionsPanel() { prompt = new JLabel ("Choose your input option:"); prompt.setFont (new Font ("Courier New", Font.BOLD, 24)); one = new JRadioButton ("Enter A Transaction"); one.setBackground (Color.red); two = new JRadioButton ("List All Transactions"); two.setBackground (Color.GREEN); three = new JRadioButton ("List All Checks"); three.setBackground (Color.Blue); four = new JRadioButton ("List All Deposits"); four.setBackground (Color.yellow); five= new JRadioButton ("List All Service Charges"); five.setBackground (Color.magenta); ButtonGroup group = new ButtonGroup(); group.add (one); group.add (two);
  • 11.
    group.add (three); group.add (four); group.add(five); EOptionListener listener = new EOptionListener(); one.addActionListener (listener); two.addActionListener (listener); three.addActionListener (listener); four.addActionListener (listener); five.addActionListener (listener); // add the components to the JPanel add (prompt); add (one); add (two); add (three); add (four); add (five); setBackground (Color.green); setPreferredSize (new Dimension(400, 140)); } //***************************************************************** // Represents the listener for the radio buttons //***************************************************************** private class EOptionListener implements ActionListener { //-------------------------------------------------------------- // Calls the method to process the option for which radio // button was pressed. //-------------------------------------------------------------- public void actionPerformed (ActionEvent event) { Object source = event.getSource(); if (source == one)
  • 12.
    Assignment21.inputTransactions(); else if (source ==two) Assignment21.listTransactions(); else if (source == three) Assignment21.listChecks(); if (source == four)//list deposits Assignment21.listDeposits(); if (source == five) Assignment21.listService_Charges(); } } } //------------------------------Transaction.java----------------------------------- package assignment2.pkg1; public class Transaction { private int transNumber; private int transId; private double tAmount; public Transaction(int number, int id, double amount) { transNumber = number; transId = id; tAmount = amount; } public int getTransNumber() { return transNumber; }
  • 13.
    public int getTransId() { returntransId; } public double getTransAmount() { return tAmount; } }