Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class named Done and in that class, Write a function named isEven which

ID: 3606803 • Letter: C

Question

Create a class named Done and in that class,

Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd.

Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the event of a tie. Note that Math.abs(n) returns the absolute value of a number.

Write a method called sumTo that takes two int parameters and returns an int. This function should return the sum of all numbers from the smaller parameter to the larger parameter, inclusive. (i.e. given 2 and 4, returns 9. Because 2 + 3 + 4 = 9) (if given 4 and 2, returns 9 as well. Because 2 + 3 + 4 = 9)

Write a method named rollSnakeEyes which takes no parameters and does not return any value. This method should continually roll two dice and only terminate when both dice are equal to 1. You must roll both dice at the same time. For example, if one die is 1 you can not only roll the other die. For example, if one die is 1 you can not only roll the other die. Print the result of each roll to the console. (So if die one was a 4 and die two was a 6, print "4   6" to the console). Use '(int)(Math.random() * 6) + 1' to simulate a dice roll. (That code will always produce an int between 1 and 6)

When you are finished, submit Done.java

Explanation / Answer

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

______________

Done.java

import java.util.Random;

public class Done {

//This method will check whether the number is even or odd
public boolean isEven(int num) {
if (num % 2 == 0)
return true;
else
return false;
}
//This method will find the number close to 10
public int close10(int num1, int num2) {
if (Math.abs(10 - num1) < Math.abs(10 - num2))
return num1;
else if (Math.abs(10 - num1) > Math.abs(10 - num2))
return num2;
else
return 0;
}

//This method will find the sum of numbers between the two parameters(inclusive)
public int sumTo(int num1, int num2) {
int sum = 0;
for (int i = num1; i <= num2; i++) {
sum += i;
}
return sum;
}

//This method will display the dice nos
public void rollSnakeEyes() {
Random r = new Random();
int die1 = (int)(Math.random() * 6) + 1;
int die2 = (int)(Math.random() * 6) + 1;
while (!(die1 == 1 && die2 == 1)) {
System.out.println(""" + die1 + " " + die2 + """);
die1 = (int)(Math.random() * 6) + 1;
die2 = (int)(Math.random() * 6) + 1;
}
}
}

_____________________

Test.java

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

//Declaring variables

int num1, num2 = 0;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Creating an instance of Done class

Done d = new Done();

//Getting the input entered by the user

System.out.print("Enter a number to check even or not :");

num1 = sc.nextInt();

//calling the method to check whetehr the number is even or not

if (d.isEven(num1))

System.out.println(num1 + " is even number.");

else

System.out.println(num1 + " is not an even number.");

System.out.print("Enter first number :");

num1 = sc.nextInt();

while (true) {

System.out.print("Enter second number :");

num2 = sc.nextInt();

if (num2 <= num1) {

System.out.println("Second number must be greate than " + num1);

continue;

} else

break;

}

//calling the method to display the number close to 10

if (d.close10(num1, num2) != 0) {

System.out.println("The number which is close to 10 is :" + d.close10(num1, num2));

} else {

System.out.println("Both numbers are same");

}

System.out.println("The Sum of numbers between " + num1 + " and " + num2 + " is :" + d.sumTo(num1, num2));

d.rollSnakeEyes();

}

}

___________________

Output:

Enter a number to check even or not :46
46 is even number.
Enter first number :3
Enter second number :2
Second number must be greate than 3
Enter second number :5
The number which is close to 10 is :5
The Sum of numbers between 3 and 5 is :12
"4 5"
"6 1"
"5 4"
"5 6"
"6 3"
"4 3"
"2 4"
"6 6"
"3 6"
"2 2"
"2 3"
"4 6"
"3 6"
"4 2"
"5 2"
"2 3"
"6 1"
"1 6"

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote