Question

You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int...

You only need to use Junit to test 3 methods of the Nurse class.

public Nurse(int a, float s) { ... }
public boolean isBusy() {...}
public void retire() {....}

code:

public class Nurse {
   private int numOfPatients;
   private float salary;

   // Helping function
   // private void trace(char* s) { cout << s << endl; }

   // Implementor function
   public Nurse(int a, float s) { numOfPatients =a; salary=s; }

   // Access function
   public int getNumOfPatients() { return numOfPatients; }
   public float getSalary() {  return salary; }
   public void  setNumOfPatients(int a) {   numOfPatients=a; }
   public void  setSalary(float s) {   salary=s; }
   public boolean isBusy() {
         // trace("predicate");
         return numOfPatients > 30;
   }

   // Implentor function
   public void retire() {
      // trace("implementor");
      numOfPatients=0
      salary=0;
   }
   public void payRaise(float raise) {
      // trace("implementor");
      salary += raise;
   }

   public static void main(String atgv[])
   {
      Nurse mary= new Nurse(25, 80000);
      if (mary.isBusy())
         System.out.println("Mary is busy");
      else
         System.out.println("Mary is not busy");
      mary.payRaise(3000);
      System.out.println("Mary's salary is " + mary.getSalary());
      mary.retire();
      System.out.println("Mary has " 
             + mary.getNumOfPatients() 
             + " of patients after she retired.");
   }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Testlogic {
public void   testEquals(){
       final int value = 25;
   final float value1 = 80000;

   Nurse mary = new Nurse(value,value1);   
   assertEquals(4,Nurse(value,value1);
   assertEquals(-1,Nurse(value,value1);
   }
   public void isBusy(){
   assertEquals(4,Nurse.isBusy());
   assertEquals(-1,Nurse.isBusy());
   }
   public void retire(){
   assertEquals(4,Nurse.retire());
   assertEquals(-1,Nurse.retire());
   }
}

Add a comment
Know the answer?
Add Answer to:
You only need to use Junit to test 3 methods of the Nurse class. public Nurse(int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Junit test for the following class below: public class Player {       public int...

    Write Junit test for the following class below: public class Player {       public int turnScore;    public int roundScore;    public int lastTurnScore;    public String name;    public int chipPile;       public Player (String name) {        this.name = name;        this.turnScore = 0;        this.chipPile = 50;    }          public int getChip() {        return chipPile;    }       public void addChip(int chips) {        chipPile...

  • Write Junit test for the following class below: public class Player {       public int turnScore;    public int roundScore;    public int lastTurnScore;    public String name;    public int chipPile;...

    Write Junit test for the following class below: public class Player {       public int turnScore;    public int roundScore;    public int lastTurnScore;    public String name;    public int chipPile;       public Player (String name) {        this.name = name;        this.turnScore = 0;        this.chipPile = 50;    }          public int getChip() {        return chipPile;    }       public void addChip(int chips) {        chipPile += chips;    }       public int getRoundScore() {        return roundScore;    }       public void setRoundScore(int points) {        roundScore += points;    }       public int getTurnScore() {        return turnScore;   ...

  • Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {...

    Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {        dice = new Dice();    }    public Turn(Dice dice) {        this.dice = dice;    }       public void turnRoll()    {        dice.roll();        if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2)        {            turnScore = 0;            isSkunk = true;        }        else if (dice.getLastRoll() == 2)        {            turnScore = 0;            isDoubleSkunk = true; }        else        {           ...

  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

  • C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer)...

    C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...

  • Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAn...

    Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() {    return question; } //This function takes answer from user public void answer(String userAnswer) {    // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...

  • Create Junit tests for the following classes public class Dice {    private Die die1;    private Die die2;    public Dice()    {        this.die1 = new Die();        this.die2 = new Die();    }    pu...

    Create Junit tests for the following classes public class Dice {    private Die die1;    private Die die2;    public Dice()    {        this.die1 = new Die();        this.die2 = new Die();    }    public Dice(int[] programmedRolls)    {        int[] programmableroll = programmedRolls;        this.die1 = new Die(programmableroll);        this.die1 = new Die(programmableroll);           }       public Dice(Die die1, Die die2)    {        this.die1 = die1;        this.die2 = die2;    }       public void roll() {        die1.roll();        die2.roll();    }       public int getDie1Value() {        return die1.getLastRoll();    }       public int getDie2Value() {        return die2.getLastRoll();    }      ...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {    super();    System.out.println(“B() called”);...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {   super();   System.out.println(“B() called”); } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT