Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package console_apps; import java.util.Scanner; import model.Utilities; public class GetSequenceApp { public static void main(String[] args) { Scanner input = new Scanner(System.in); /* Prompt the user

package console_apps;
import java.util.Scanner;
import model.Utilities;
public class GetSequenceApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/* Prompt the user for input bounds. */
System.out.println("Enter an integer lower bound:");
int lower = input.nextInt();
System.out.println("Enter an integer upper bound:");
int upper = input.nextInt();
/* Invoke the utility method for calculation. */
String result = Utilities.getNumbers(lower, upper);
/* Output the result. */
System.out.println(result);
input.close();
}
}
package model;
public class Utilities {
/*
* Input parameters:
* - `lower` is the lower bound
* - `upper` is the upper bound
*
* Use of arrays or any Java library class (e.g., ArrayList) is strictly forbidden.
* Violation of this will result in a 50% penalty on your marks.
* Try to solve this problem using loops only.
*
* Refer to you lab instructions for what the method should return.
*/
public static String getNumbers(int lower, int upper) {
String result = "";
/* Your implementation of this method starts here.
* Recall from Week 1's tutorial videos:
* 1. No System.out.println statements should appear here.
* Instead, an explicit, final `return` statement is placed for you.
* 2. No Scanner operations should appear here (e.g., input.nextInt()).
* Instead, refer to the input parameters of this method.
*/
/* Your implementation ends here. */
return result;
}
image text in transcribed
2.2.1 Method to Implement: getNumbers Problem. You are asked to implement a utility method which takes two integer bounds (lower and upper) and returns a string consisting of all numbers between the two bounds, inclusively Requirement. It is strictly forbidden for you to use arrays or any library class (e.g., ArrayList). Violating this requirement will cause a 50% penalty on your lab marks. Testing. Your goal is to pass all tests related to this method in the JUnit test class TestUtilities. These tests document the expected values on various cases: study them while developing your code. However, use the console application class GetSequenceApp if you wish (eg, use the input and expected values from the JUnit tests). Here are two example runs: Enter an integer lower bound: 88 Enter an integer upper bound: 88 1 number between 88 and 88: Enter an integer lower bound: 23 Enter an integer upper bound: 28 6 numbers between 23 and 28: Todo. Implement the Utilities.getNumbers method. See the comments there for the input parameters and requirements. The String return value must conform to the expected format: There are two possible errors: 1) when not both bounds are non-negative (0); and 2) when the lower bound is not less than or equal to the upper bound. What if both error conditions hold simultaneously (eg., lower 5 and upper -3, lower -3 and upper - 5)? In this case, error condition 1) takes the priority. That is, error condition 2) should only be checked when condition 1) is not the case (ie, both bounds are non-negative). See the JUnit tests. Notice that the second word in the output may be either singular (number) or plural (numbers, when there are more than one numbers in the sequence). Each number in the sequence is wrapped differently: wrapped by round parentheses if the member is a multiple of 3 (0.8. (24)); wrapped by square brackets if the number is some multiple of 3 plus one (es. [25]); and wrapped by a pair of curly bracen if the number is some multiple of 3 plus two (08 (26)). All wrapped numbers are separated by commar (.). There is one space after each comma

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

4. What will the team agreement contain?

Answered: 1 week ago