public class Number {    private int num;        public Number(int n) {       num = n;    }    /* Type your code here */        public int getNum() {       return num;    }        public void setNum(int n) {       num = n;    }    public static void main(String [] args) {       Number yourNum = new Number(723);       System.out.print(yourNum);    } }

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

public class Number {
   private int num;
   
   public Number(int n) {
      num = n;
   }

   /* Type your code here */
   
   public int getNum() {
      return num;
   }
   
   public void setNum(int n) {
      num = n;
   }

   public static void main(String [] args) {
      Number yourNum = new Number(723);
      System.out.print(yourNum);
   }
}

Write a toString() method for the Number class, which returns a String representation of a Number object. The String should be in the
format "The value is yourNum", where yourNum is the value of the integer instance field from the Number class.
Ex: If the input is:
723
then the output is:
The value is 723
Your Number.java file must define the method:
public String toString()
Transcribed Image Text:Write a toString() method for the Number class, which returns a String representation of a Number object. The String should be in the format "The value is yourNum", where yourNum is the value of the integer instance field from the Number class. Ex: If the input is: 723 then the output is: The value is 723 Your Number.java file must define the method: public String toString()
LAB
ACTIVITY
ANM&6789
1 import java.util.Scanner;
2
3 public class LabProgram {
4
5
26.21.1: LAB: The toString() method
10
11 }
Current file: LabProgram.java
public static void main(String [] args) {
Scanner scnr = new Scanner (System.in);
int inputNum = scnr .nextInt();
Number yourNum = new Number(inputNum);
System.out.print(yourNum);
}
Transcribed Image Text:LAB ACTIVITY ANM&6789 1 import java.util.Scanner; 2 3 public class LabProgram { 4 5 26.21.1: LAB: The toString() method 10 11 } Current file: LabProgram.java public static void main(String [] args) { Scanner scnr = new Scanner (System.in); int inputNum = scnr .nextInt(); Number yourNum = new Number(inputNum); System.out.print(yourNum); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage