Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1. Write your solution in file Q1.java. Use Q1Test.java to test your solution. Write a Java program which asks the user to enter an

Question 1. Write your solution in file Q1.java. Use Q1Test.java to test your solution. Write a Java program which asks the user to enter an integer number. You should create a java method is Prime which takes an integer input and returns boolean. is Prime method returns true if given number is prime, otherwise it returns false. The program prints all the prime numbers which are less than that integer number.

Hint: A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Example

Please enter a number:

10 2 3

5

7

Please enter a number:

45 2 3

5 7 11 13 17 19 23 29 31 37 41 43 

Q1Test.java?:

import java.io.IOException; import java.io.PrintWriter;

import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runner.JUnitCore; import org.junit.runner.Result;

public class Q1Test extends student.TestCase {

static JUnitCore junitCore; static Class testClasses;

double s = 5; double a = 2.5;

@Test public void testCase1() { setSystemIn("3", "2", "0"); Q1.main(null); assertEquals("Enter a number: Enter a number: Enter a number: You have entered 2 numbers. Sum = " + s + " Average = " + a + " ", systemOut().getHistory()); }

double s1 = -6; double a1 = -2;

@Test public void testCase2() { setSystemIn("-5", "-3", "2", "0"); Q1.main(null); assertEquals( "Enter a number: Enter a number: Enter a number: Enter a number: You have entered 3 numbers. Sum = " + s1 + " Average = " + a1 + " ", systemOut().getHistory()); }

double i2 = 1.5;

@Test public void testCase3() { setSystemIn(i2 + "", "0"); Q1.main(null); assertEquals("Enter a number: Enter a number: You have entered 1 numbers. Sum = " + i2 + " Average = " + i2 + " ", systemOut().getHistory()); }

}

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

What is management growth? What are its factors

Answered: 1 week ago