Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( The EvenNumber class ) Define the EvenNumber class for representing an even number. The class contains: A data field value of the int type

(The EvenNumber class) Define the EvenNumber class for representing an
even number. The class contains:
A data field value of the int type that represents the integer value
stored in the object.
A no-arg constructor that creates an EvenNumber object for the value
0.
A constructor that constructs an EvenNumber object with the specified
value. If the value is not even, throw a RuntimeException with
message "value not even".
A function named getvalue () to return an int value for this object.
A function named getNext () to return an EvenNumber object that
represents the next even number after the current even number in this
object.
A function named getPrevious () to return an EvenNumber object
that represents the previous even number before the current even
number in this object. Must start with
import java.util.Scanner;
public class Exercise12_08Extra {
public static void main(String[] args){
try {
System.out.print("Enter an integer: ");
Scanner input = new Scanner(System.in);
int intValue = input.nextInt();
EvenNumber evenNumber = new EvenNumber(intValue);
System.out.println("Current number is "+ evenNumber.getValue());
System.out.println("Next even number is "
+ evenNumber.getNext().getValue());
System.out.println("Previous even number is "
+ evenNumber.getPrevious().getValue());
}
catch (RuntimeException ex){
System.out.println(ex);
}
}
}
class EvenNumber {
// WRITE YOUR CODE HERE
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago