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

help? Problem 22) Below is the outline of a simple class called Busywork. In the

ID: 3607552 • Letter: H

Question

help?

Problem 22) Below is the outline of a simple class called Busywork. In the blank space provided in e elass add two methods to the class. The two methods that you add can make use of the two gven methods setNumber() and getNumber(). (a) Add a method increment() that adds 1 to the value of m. (b) Add a method decrement() that returns a Busywork object whose value of m is one less than the value stored in the calling object. This method should not modify the m in the object the method is called on class Busywork private int m e; public void setNumber(int newM) this·m newM; = public int getNumber() return this.m; // write the methods increment() and decrement() )//BusyWork

Explanation / Answer


class BusyWork{
    private int m = 0;
    public void setNumber(int newM){
        this.m = newM;
    }
    public int getNumber(){
        return this.m;
    }
  
    public void increment(){
        //m++ means increment m by 1
        m++;
    }
  
    public BusyWork decrement(){
        //create a newe BusyWrok object
        BusyWork n = new BusyWork();
        //Set it's m to m-1
        n.m = this.m-1;
        return n;
    }
}