In number theory, a value can be categorized as a natural number (a whole number >0, often denoted ℕ), an integer (zero or a positive or negative whole number, including the natural numbers, often denoted ℤ), or a real number (which includes the natural numbers and integers, along with all other positive and negative numbers that are not integers, often denoted ℝ). a) write a definition for a number class that contains: (i) A single field suitable for storing either a natural number, or an integer, or a real number; (ii) Setter and getter methods for manipulating this field; (iii) A constructor that initializes new objects of number to have the value 1 (unity); (iv) a method that determines which kind of number is currently stored (returning 0 if the number is real and an integer and a natural number, 1 if the number is real and integer but not a natural number, and 2 if the number is real but neither an integer nor a natural number)
In number theory, a value can be categorized as a natural number (a whole number >0,
often denoted ℕ), an integer (zero or a positive or negative whole number, including the
natural numbers, often denoted ℤ), or a real number (which includes the natural numbers
and integers, along with all other positive and negative numbers that are not integers, often
denoted ℝ).
a) write a definition for a number class that contains:
(i) A single field suitable for storing either a natural number, or an integer, or a real
number;
(ii) Setter and getter methods for manipulating this field;
(iii) A constructor that initializes new objects of number to have the value 1 (unity);
(iv) a method that determines which kind of number is currently stored (returning 0 if
the number is real and an integer and a natural number, 1 if the number is real and integer
but not a natural number, and 2 if the number is real but neither an integer nor a natural
number)
Java code needed
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images