Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!