Question: JAVASCRIPT Second partial assignment for hw2. This means that controllers should be written for the controller package and GUI classes (most likely just the view
JAVASCRIPT
Second partial assignment for hw2. This means that controllers should be written for the controller package and GUI classes (most likely just the view classes) for the view package. As you implement the rest of the MVC architecture you should test its functionality manually, by running your application and checking its behavior. You can consider this as acceptance testing, as if a client tests your application.
1. Controller package Controller classes should extend AbstractController class. There should be a controller class per a view. So, at least two controllers: for AccountSelectionView and AccountView. Also, there should be an instance of a controller per an instance of a view. For instance, if two instances of AccountView are open on a single account then each should have an instance of a controller. A controller in the Calculator example can be used for reference. As you can see it has a dispatcher method called "operation" that takes a string as input (this string describes the UI component) and decides on a manipulation of the model in a series of "if then else" statements.
2. View package View classes should extend the abstract JFrameView. There should be at least two view classes, say, AccountSelectionView and AccountView. While in general, classes for UI components other than the view (i.e. application window) can be in the view package, in our simple application subclasses of JFrameView are enough. You can use CalculatorView as an example to write subclasses of JFrameView. It shows how basic Swing classes can be used to implement a UI with a JTextField, JButtons, a hierarchy of UI components via JPanel classes with GridBagLayout. It also shows the use of an ActionListener to implement interactivity. AccountSelectionView will need a JComboBox too. Its example was in Java Foundations code, for instance, the JukeBox example. Also use Calculator example to see how instances of MVC related classes are instantiated, the sequence in which the instantiations are done. You can place the main method in the AccountSelectionView class (similar to Calculator example) or in a dedicated Main class. Please note that the View classes register as listeners in the corresponding model classes in the constructor of JFrameView class. If your view class does not subclass from JFrameView they will not register as listeners. You can implement currency conversions in an AccountView class. For acceptance testing:
1. Check that while several account windows are open on a single account, they all change the balance properly if a withdraw or deposit is made in one of them. This should check that MVC communication functions properly.
2. Please also test that withdrawing more funds than available results in an exception and a corresponding pop-up window is shown.
3. If you close the account selection window, all the currently open windows of your application should be closed.
4. When closing the application, the current account balances should be saved to a file.
Here is my model
//Abstract Model.java
package acc.model;
import java.util.List;
import java.util.ArrayList;
public abstract class AbstractModel implements Model {
private List
public void notifyChanged(ModelEvent event) {
for(ModelListener ml : listeners){
ml.modelChanged(event);
}
}
public void addModelListener(ModelListener l){
listeners.add(l);
}
public void removeModelListener(ModelListener l){
listeners.remove(l);
}
}
//Account1List.java
package acc.model;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.*;
public class Account1List extends ArrayList
/**
*
*/
private static final long serialVersionUID = 1L;
private static List
private AgentModel account;
private Formatter x;
public void MakeAccount(String Name, int ID, BigDecimal Balance ) {
AgentModel act = new AgentModel(Name, ID, Balance);
AccountLists.add(act);
}
public void removeAccounts(int inp){
account = AccountLists.get(inp);
AccountLists.remove(account);
}
public void SaveList() throws IOException {
/*FileWriter fw = null;
fw = new FileWriter (file);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter outFile = new PrintWriter(bw);*/
try {
x= new Formatter("Accounts.txt");
account = AccountLists.get(0);
int ID = account.getID();
String name = account.getName();
BigDecimal Balance = account.getBalance();
x.format("%s %d %s", name, ID ,Balance.toString());
x.close();
System.out.println("File Made");
//outFile.print("ID: " + ID +"Name: " + name + "Balance: " + Balance);
//outFile.println();
}
catch (Exception e) {
System.out.println("No list found");
}
}
}
//AgentModel.java
package acc.model;
import java.math.BigDecimal;
public class AgentModel extends AbstractModel {
private static final AgentStatus AgentStatus = null;
private String Name;
private int ID;
private BigDecimal Balance;
public AgentModel(String inputName, int inputID, BigDecimal inputBalance)
{
Balance = inputBalance;
ID = inputID;
Name = inputName;
}
public void withdrawl(BigDecimal amount) throws OverdrawException
{
if( amount.compareTo(Balance) < 0 )
throw new OverdrawException("You are withdrawling more money than you have! Cannot have negative balance.");
else
Balance = Balance.subtract(amount);
//final ModelEvent me = new ModelEvent(ModelEvent.EventKind.BalanceUpdate, new BigDecimal(Balance), AgentStatus agSt);
}
public void deposit (BigDecimal amount)
{
Balance = Balance.add(amount);
}
public int getID()
{return ID;}
public String getName()
{return Name;}
public BigDecimal getBalance ()
{
return Balance;
}
}
//AgentStatus.java
package acc.model;
public enum AgentStatus {
Running, Blocked, Paused, NA
}
//Model.java
package acc.model;
public interface Model {
public void notifyChanged(ModelEvent me);
}
//ModelEvent.java
package acc.model;
public class ModelEvent {
public enum EventKind {
BalanceUpdate, AgentStatusUpdate, AmountTransferredUpdate
}
private EventKind kind;
private double balance;
private AgentStatus agSt;
public ModelEvent(EventKind kind, double balance, AgentStatus agSt){
this.balance = balance;
this.kind = kind;
this.agSt = agSt;
}
public EventKind getKind(){return kind;}
public double getBalance(){
return balance;
}
public AgentStatus getAgStatus(){return agSt;}
public Object getActionCommand() {
// TODO Auto-generated method stub
return null;
}
}
//ModelListener.java
package acc.model;
public interface ModelListener {
public void modelChanged(ModelEvent me);
}
//OverdrawlException.java
package acc.model;
public class OverdrawException extends Exception{
/**
*
*/
private static final long serialVersionUID = 1L;
public OverdrawException (String s)
{
super(s);
System.out.println(s);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
