Below is the outline of a simple class called BusyWork. In the blank space provi
ID: 3763255 • Letter: B
Question
Below is the outline of a simple class called BusyWork. In the blank space provided in the class, add two methods to the class. The two methods that you add can make use of the two given 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
{ int m = 0;
public void setNumber(int newM)
{
this.m = newM;
}
public int getNumber()
{
return this.m;
} // write the methods increment() and decrement()
}//BusyWork
Explanation / Answer
public class Number
{
private int m ;
public void setName(int m)
{
m=n;
}
public String get m()
{
return m;
}
public static void incrementAndDecrement()
{
int m= 0;
for(int i = 10; i >= 0; i--)
{
System.out.println(i);
System.out.println(m);
m++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.