Question
Exercise 1: Detecting prime numbers Write a class to determine whether the numeric value in its instance variable is prime and writes a message to
Exercise 1: Detecting prime numbers
Write a class to determine whether the numeric value in its instance variable is prime and writes a message to standard output stream stating whether the number is prime or not. For example, if the value is 36, the program displays "36 is not prime." If the value is 37, the program displays "37 is prime."
Develop 8 test cases in a tester class to verify that your program runs correctly for them. The test cases should contain some prime numbers as well as non-prime values. Include test cases (0, 1, negative numbers) that try to break your program so that you are sure you have implemented the code correctly.
Make sure comments are consistent with javadoc standard and easy to read and understand.
Exercise 2: Listing prime numbers
Write a class that reads a positive integer entered by the user, computes and displays all the prime numbers between 2 and the number entered (inclusive) using the class implemented in exercise 2.
Make sure comments are consistent with javadoc standard and easy to read and understand.
Exercise 3: Factoring numbers
Write a java program with one or more classes that asks the user to enter a positive integer greater than 1. The program computes the prime factors of the number and prints them. For example, if the user enters 140, the program displays 2 2 5 7.
Develop 8 test cases and verify that your program runs correctly for them. The test cases should contain some edge cases: prime numbers v.s. non-prime numbers, positive numbers v.s. negative numbers.
Make sure comments are consistent with javadoc standard and easy to read and understand.
Exercise 4: Generating random colors
Write a java program that generates a different list of 100 random RGB color values using hexadecimal notation. The program should output something like the following to the console.
33AAE3
A87E32
... 98 additional RGB values
To solve this problem you need to generate strings with 6 characters where each character is randomly chosen from the following set of symbols.
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }
You need to scale up (for Math.random()) or down (for Random class) the output from a random number generator appropriately to get a random integer between 0 and 15.
Make sure comments are consistent with javadoc standard and easy to read and understand.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started