Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SHould create test case with java uni t and keep gettig error code public class

ID: 3555794 • Letter: S

Question

SHould create test case with java unit and keep gettig error

code

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() {
   super(); /**constructs a new instance of a this class*/
   /** 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: ");

       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: ");
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;
   }
  
      
     
}

controll

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());
       }
     
  
}
  

patter

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());
       }
     
  
}
  

TEst

package model;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
/**
* @author secc
*
*/
public class AccountModelTest {


@Test
public void testGetId() {
AccountModel test= new AccountModel();
test.setId("dp1202");
assertEquals("dp1202", test.getId());
// TODO
}

@Test
public void testGetName() {
AccountModel test= new AccountModel();
test.setName("angela");
assertEquals("angela", test.getName());// TODO
}

@Test
public void testDeposit() {
AccountModel test= new AccountModel();
assertEquals(300.0,test.deposit(300.0),0);// TODO
}


@Test
public void testWithdraw() {
AccountModel model= new AccountModel();
assertEquals(300.0,model.withdraw(300.0),0);// TODO
}


@Test
public void testEditin_euro() {
AccountModel model= new AccountModel();
assertEquals(0.0,model.editin_euro(),0.0);// TODO
}


@Test
public void testEditin_yuan() {
AccountModel model= new AccountModel();
assertEquals(0.0,model.editin_yuan(),0.0); // TODO
}


@Test
public void testGetBalance() {
AccountModel model= new AccountModel();
assertEquals(0.0, model.getBalance(),0.0);// TODO
}

}

Explanation / Answer

TRY REPLACING TEST CLASS WITH THIS PLEASE :

import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author secc
*
*/
public class AccountModelTest {

@Test
public void testGetId() {
AccountModel test= new AccountModel();
test.setId("dp1202");
assertEquals("dp1202", test.getId());
}
@Test
public void testGetName() {
AccountModel test= new AccountModel();
test.setName("angela");
assertEquals("angela", test.getName());
}

@Test
public void testDeposit() {
AccountModel test= new AccountModel();
assertEquals((int)(300.0),(int)test.deposit(300.0));
}

@Test
public void testWithdraw() {
AccountModel model= new AccountModel();
assertEquals((int)300.0,(int)model.withdraw(300.0));
}

@Test
public void testEditin_euro() {
AccountModel model= new AccountModel();
assertEquals((int)0.0,(int)model.editin_euro());
}

@Test
public void testEditin_yuan() {
AccountModel model= new AccountModel();
assertEquals((int)0.0,(int)model.editin_yuan());
}

@Test
public void testGetBalance() {
AccountModel model= new AccountModel();
assertEquals((int)0.0, (int)model.getBalance());
}
}