Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 1: Edit Mod.java Download the Mod.java file, and open it in jGrasp (or a text editor of your choice). You will need to implement

Step 1: Edit Mod.java

Download the Mod.java file, and open it in jGrasp (or a text editor of your choice). You will need to implement a method that uses modulo (%) to make the code correctly compile and run. You may not modify the code in the main method. Example output of the program is shown below, with user input shown in bold:

Enter an integer: 2 Enter a second integer: 3 Result: 2 

File:

import java.util.Scanner; public class Mod { // TODO - write your code below this comment. // You need to write a method that will allow this // to compile and return the correct result when run. // // The method you need to write is called in main. // As a hint, try to figure out what method specification // you'll need in order to make this compile. You will // need to use the modulus (%) operator to get the first // value modulus the second value. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int first = input.nextInt(); System.out.print("Enter a second integer: "); int second = input.nextInt(); System.out.println("Result: " + modBoth(first, second)); } }

Step 2: Open ModTest.java as a Test File, and Edit It

Download the ModTest.java file, being sure to put it in the same folder/directory as your Mod.java file. This file contains a number of tests for the method you wrote in the previous step. Open this file in jGrasp as a test file, using the same instructions you used in the previous lab. You need to write a number of tests in this file, and all of them must pass. The comments in the file provide more details.

File:

import static org.junit.Assert.assertEquals; import org.junit.Test; public class ModTest { @Test public void zeroModOneIsZero() { assertEquals(Mod.modBoth(0, 1), 0); } @Test public void oneModOneIsZero() { assertEquals(Mod.modBoth(1, 1), 0); } @Test public void twoModOneIsZero() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 2 and 1, and // then use assertEquals to ensure that // the result is 0. } @Test public void twoModTwoIsZero() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 2 and 2, and // then use assertEquals to ensure that // the result is 0. } @Test public void threeModTwoIsOne() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 3 and 2, and // then use assertEquals to ensure that // the result is 1. } @Test public void fiveModTwoIsOne() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 2, and // then use assertEquals to ensure that // the result is 1. } @Test public void fiveModThreeIsTwo() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 3, and // then use assertEquals to ensure that // the result is 2. } @Test public void fiveModFourIsOne() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 4, and // then use assertEquals to ensure that // the result is 1. } @Test public void fiveModFiveIsZero() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 5, and // then use assertEquals to ensure that // the result is 0. } @Test public void fiveModSixIsFive() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 6, and // then use assertEquals to ensure that // the result is 5. } @Test public void fiveModSevenIsFive() { // TODO - write your code below this comment. // The code should call the Mod.modBoth // method with the parameters 5 and 7, and // then use assertEquals to ensure that // the result is 5. } }

Step 3: Edit IntCompare.java

Download the IntCompare.java file, and open it in jGrasp (or a text editor of your choice). You will need to implement two methods in this file which return boolean results, reflecting whether or not one value is greater than or less than another. The comments in the file provide more details. You may not modify the code in the main method. Example output of the program is shown below, with user input shown in bold:

Enter first integer: 2 Enter second integer: 3 Less than: true Greater than: false 

Further example output of the program is shown below, with user input shown in bold:

Enter first integer: 2 Enter second integer: 2 Less than: false Greater than: false 

File:

import java.util.Scanner; public class IntCompare { // TODO - write your code below this comment. // You need to define two static methods, described below: // // 1.) // - The method's name is firstIsLessThanSecond // - The method's return type is boolean // - The method's first parameter is an int // - The method's second parameter is an int // - The method returns true if the first int is less than // the second, else false. // // 2.) // - The method's name is firstIsGreaterThanSecond // - The method's return type is boolean // - The method's first parameter is an int // - The method's second parameter is an int // - The method returns true if the first int is greater than // the second, else false. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first integer: "); int first = input.nextInt(); System.out.print("Enter second integer: "); int second = input.nextInt(); System.out.println("Less than: " + firstIsLessThanSecond(first, second)); System.out.println("Greater than: " + firstIsGreaterThanSecond(first, second)); } }

Step 4: Open IntCompareTest.java as a Test File, and Edit It

Download the IntCompareTest.java file, being sure to put it in the same folder/directory as your IntCompare.java file. This file contains a number of tests for the methods you wrote in the previous step. Open this file in jGrasp as a test file, using the same instructions you used in the previous lab. You need to write a number of tests in this file, and all of them must pass. The comments in the file provide more details.

File:

import static org.junit.Assert.assertEquals; import org.junit.Test; public class IntCompareTest { @Test public void testLessThanIsLessThan() { assertEquals(true, IntCompare.firstIsLessThanSecond(0, 1)); } @Test public void testLessThanNotLessThan() { assertEquals(false, IntCompare.firstIsLessThanSecond(1, 0)); } // You will need to write TWO tests: // 1.) A test to make sure that firstIsGreaterThanSecond returns // true if the first parameter is greater than the second // 2.) A test to make sure that firstIsGreaterThanSecond returns // false if the first parameter is not greater than the second // TODO - write your code below this comment. }

Step 5: Edit MinMax.java

Download the MinMax.java file, and open it in jGrasp (or a text editor of your choice). This code in this file does something much like IntCompare.java, only now it needs to return int values instead of boolean values. The comments in the file provide more details. You may not modify the code in the main method. Example output of the program is shown below, with user input shown in bold:

Enter first integer: 3 Enter second integer: 4 Min: 3 Max: 4 

Further example output of the program is shown below, with user input shown in bold:

Enter first integer: 1 Enter second integer: 1 Min: 1 Max: 1 

File:

import java.util.Scanner; public class MinMax { // You need to write two methods: min and max. // min should take two ints and return the smaller one, // and max should take two ints and return the larger one. // If the two ints given are the same, then they can return // either one. // // As a hint, you will need to use if/else, along with // a comparison of some sort between the two given ints. // DO NOT CALL Math.min OR Math.max! // TODO - write your code below this comment. // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first integer: "); int first = input.nextInt(); System.out.print("Enter second integer: "); int second = input.nextInt(); System.out.println("Min: " + min(first, second)); System.out.println("Max: " + max(first, second)); } }

Step 6: Open MinMaxTest.java as a Test File, and Edit It

Download the MinMaxTest.java file, being sure to put it in the same folder/directory as your MinMax.java file. This file contains a number of tests for the methods you wrote in the previous step. Open this file in jGrasp as a test file, using the same instructions you used in the previous lab. You need to write a number of tests in this file, and all of them must pass. The comments in the file provide more details.

import static org.junit.Assert.assertEquals; import org.junit.Test; public class MinMaxTest { // There are SIX tests in total which you must write. // The comments below discuss these, three at a time. // There are three behaviors of interest for MinMax.min: // // 1. If the first parameter is smaller than the second, the // first parameter is returned. // 2. If the first parameter is equal to the second, either // parameter is returned // 3. If the first parameter is greater than the second, the // second parameter is returned. // // For each of the above behaviors, write a test that makes sure // that MinMax.min actually shows the behavior of interest. // TODO - write your code below this comment. // There are three behaviors of interest for MinMax.max: // // 1. If the first parameter is greater than the second, the // first parameter is returned. // 2. If the first parameter is equal to the second, either // parameter is returned // 3. If the first parameter is less than the second, the // second parameter is returned. // // For each of the above behaviors, write a test that makes sure // that MinMax.max actually shows the behavior of interest. // TODO - write your code below this comment. }

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

More Books

Students also viewed these Databases questions

Question

what does (\d*.\d+)|(\d+\.\d*) mean in regular expression regex

Answered: 1 week ago

Question

Describe the range of reactions to the death of a loved one.

Answered: 1 week ago

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago