Question: This problem will test your ability to convert a specification to a program as well as follow instructions. Read all instructions carefully. Any deviation will

This problem will test your ability to convert a specification to a program as well as follow instructions. Read all
instructions carefully. Any deviation will count against you.
Problem Description
There is a set of base-10 numbers that are referred to as happy numbers. There is also a set of numbers that are
referred to as prime numbers. The intersection of those sets (happy numbers that are also prime) are called happy
prime numbers.
10-Happy Numbers
A Happy Number n is defined by the following process. Starting with n, replace it with the sum of the squares of its
digits, and repeat the process until n equals 1, or it loops endlessly in a cycle which does not include 1. Those numbers
for which this process ends in 1 are Happy Numbers, while those that do not end in 1 are unhappy numbers.
First few happy numbers are 1,7,10,13,19,23,28,31,32,44,49,68,70,79,82,86,91,94,97,100
Example:
Assignment
Write a program to print the first N happy prime numbers where N is input from the user via the console. The numbers
should be printed one per line. Your program must consist of three classes named as follows:
1) public class HappyNumber
a) Contains the function
public static boolean isHappy(int n) throws IllegalArgumentException
Returns true if n is happy, false if it is not, throws an exception if n is less than 0
b) Contains any other private functions that you deem necessary
2) public class PrimeNumber
a) Contains the function
public static boolean isPrime(int n) throws IllegalArgumentException
Returns true if n is prime, false if it is not, throws an exception if n is less than 0. Note that 1 is not a prime
number, by definition.
b) Contains any other private functions that you deem necessary
3) public class MainApp
a) Contains the function
public static void main(String[] args)
Calculates and displays the first N happy-prime numbers where N is received from keyboard input. If the user
provides an invalid number for N (e.g. negative, floating point, character string...) this function should throw an
exception explaining what went wrong.
b) Contains no other functions.

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!