Question: FOR JAVA Below is the outline of a simple class called Number. Complete the missing part: (a) define a default constructor which sets m to
FOR JAVA Below is the outline of a simple class called Number. Complete the missing part: (a) define a default constructor which sets m to 0; (b) define a constructor that sets m to the value of the parameter (c)Add a method increment() that adds 1 to the value of m. (d) Add a method decrement() that returns a Number 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. (e) complete a main method to test the methods. public class Number { private int m; // (a) default constructor sets m to 0 // (b) the second constructor sets m based on the parameter public void setNumber(int newM) { m = newM; } public int getNumber() { return m; } // (c) write the method increment() // (d) write the method decrement() public static void main(String[] args) { // (e)-1: declare myNumber to be a reference variable of type Number // (e)-2: assign myNumber a number object created using default constructor // (e)-3: let myNumber to represent the number 10 by using set method
// (e)-4: printout the number represented by myNumber: should be 10
// (e)-5: assign myNumber a number object created using second constructor with parameter 5; // (e)-6: printout the number represented by myNumber: should be 5. //(e)-7 increase myNumber // (e)-8: declare a reference variable of type Number, yourNumber // (e)-9: assign to yourNumber the object returned by decrement of myNumber } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
