Reference no: EM13165100
Create account management with java gui using a MVC model.create withdraw, create account, deposit , trasfer , balance , on the main fram. and On pressing one of these buttons a window "Start deposit/withdraw for ac count: account ID suppose to show up. The accountI D should correspond to the account selected in the drop-down list of the main window when a "Create ... agent" button was pressed. " " agent window contains some editable textfield( id, amount in, operations per second On pressing per second" initialized to 0.0, it accepts only digits and a decimal point
Pleasecheck code and then fix my code, i'm kind of lost.
Model
package model;
import java.util.Scanner;
/** using MVC model to create a account management program */
/** Design Model class*/
/** A model is an object representing data or even activity*/
public class AccountModel {
private final double euro = 0.72; /** set variables*/
private final double yuan = 6.2;
private String id;
private String name;
private double balance;
public AccountModel(String id, String name, double balance) {
super(); /**constructs a new instance of a this class*/
this.id = id; /** design methods for managing account*/
this.name = name;
this.balance = balance; /** original amount of usd money*/
}
public String getId() { /** set and getting ID*/
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name; /** set and getting Name*/
}
public void setName(String name) {
this.name = name;
}
public double deposit(double amount)
{ /** design deposit method*/
System.out.print("Enter the amount of deposit:\n");
Scanner SC = new Scanner(System.in);
amount=SC.nextDouble();
try{ balance= balance+amount;
} catch(Exception e){};
/** using exception for prevent runtime error*/
return balance;
}
public double withdraw(double amount)
{
System.out.print("Enter the amount of withdraw:\n");
Scanner SC = new Scanner(System.in);
amount=SC.nextDouble(); /** design withdraw method*/
try{
balance= balance-amount;
} catch(Exception e){};
return balance;
}
public double editin_euro()
{ try{ /** translate usd to Euro*/
balance = balance * euro;}
catch(Exception e){};
return balance;
}
public double editin_yuan()
{
try{ /** translate usd to yuan*/
balance = balance / yuan;
} catch(Exception e){};
return balance;
}
public double getBalance()
{
return balance;
}
}
view
package model;
import java.util.Scanner;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/** design view class, represents the visualization of the data that model contains*/
public class AccountView extends JFrame {
AccountView(){
setTitle("Bank managemet system");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(new JButton("createAccount"),BorderLayout.CENTER);
add(new JButton("deposit"), BorderLayout.NORTH);
add(new JButton("withdraw"), BorderLayout.SOUTH);
add(new JButton("transfer"), BorderLayout.EAST);
add(new JButton("balance"), BorderLayout.WEST);
setSize(300,200);
setVisible(true);
JButton btn= new JButton("deposit");
Action_Listner listener= new Action_Listner();
btn.addActionListener(listener);
add(btn);
}
public static void main(String[] args)
{
new AccountView();
}
public void Accountview(String name,String id, Double money) {
System.out.println("Name: " + name);
System.out.println("ID: "+ id); /** Main informations for print out on screen*/
System.out.println("Balance: " + money);
}
}
Control
package model;
/**design controller class that for acting on both model and view.
* it controls the data flow into model object and updates the view
* where ever data changes. it keeps view and model seperates
*
*
*/
public class AccountController {
private AccountModel model; /** call model and view */
private AccountView view;
public AccountController(AccountModel model, AccountView view) {
this.model = model;
this.view = view; /**controllthe data flow bot model and view */
}
public void setaccountName(String name) {
model.setName(name);
}
public String getaccountName() {
return model.getName();
}
public void setaccountid(String id) {
model.setId(id);
}
public String id() {
return model.getId();
}
public Double balance()
{
return model.getBalance();
}
public void updateView() { /** updates the view information when it is changes*/
view.Accountview(model.getName(), model.getId(),model.getBalance());
}
}