I have an assignment which consists of obtaining a balance from the user, then depending on the type of transaction, return the results of their balance. It's a transaction program.
My current code:
import javax.swing.JOptionPane; public class Assignment1 { public static CheckingAccount info; public static void main(String[] args) { String balance, transcode, transamount, message; CheckingAccount info; double ibalance; balance = JOptionPane.showInputDialog ("Enter your initial balance: "); ibalance = Double.parseDouble(balance); info = new CheckingAccount(ibalance); do { int tcode; tcode = getTransCode(); if (tcode == 1) { double tamount; tamount = getTransAmt(); message = "Transaction: Check in the amount of $" + tamount+ "\n" + "Current balance: $" + info.setBalance() + public static int getTransCode() { int tcode; String transcode; transcode = JOptionPane.showInputDialog ("Enter your transaction" + " code:"); tcode = Integer.parseInt(transcode); return tcode; } public static double getTransAmt() { double tamount; String transamount; transamount = JOptionPane.showInputDialog ("Enter your trans amount:"); tamount = Double.parseDouble(transamount); return tamount; } public static _________ processCheck(___________) { } public static __________ processDeposit(___________) { } } }
public class CheckingAccount { private double balance; private double totalServiceCharge; public CheckingAccount(double number) { number = balance; totalServiceCharge= number+0.10; } public static double getBalance() { return balance; } public void setBalance(double transAmt, int tCode, double Cbalance) { if(tCode == 1) { double tamount; double cbalance; cbalance = Cbalance; double servicecharge; tamount = transAmt; cbalance = balance-tamount; } else if(tCode == 2) { double cbalance; double tamount; tamount = transAmt; cbalance = balance+tamount; } } public getServiceCharge() { return totalServiceCharge; } public void setServiceCharge(double currentServiceCharge) { totalServiceCharge = currentServiceCharge; if(tcode ==1) } } }
My question is nothing about errors or compiling.
1) As you can see on the first code, right after I construct the if loop I begin to input the current balance to the user.
How do I input the result of the current balance to the user? If you check the 2nd code, on the setBalance method the current balance is shown there. Where cbalance = balance-tamount (This is because tcode == 1 represents the user checking in an amount, thus the balance -tamount)
how do i show the cbalance to the user? The method is a void, so it cant return a value, so how do I show the user their current balance? do i have to construct a joptionpane inside the void method to show the result?
2) What are the processCheck and processDeposit helper methods for? This is from my professor's sample code, I'm confused because why do I need these 2 methods if I already have a void method of setBalance that already calculates current balance?