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 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.
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 or it loops endlessly in a cycle which does not include Those numbers
for which this process ends in are Happy Numbers, while those that do not end in are unhappy numbers.
First few happy numbers are
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:
public class HappyNumber
a Contains the function
public static boolean isHappyint n throws IllegalArgumentException
Returns true if n is happy, false if it is not, throws an exception if n is less than
b Contains any other private functions that you deem necessary
public class PrimeNumber
a Contains the function
public static boolean isPrimeint n throws IllegalArgumentException
Returns true if n is prime, false if it is not, throws an exception if n is less than Note that is not a prime
number, by definition.
b Contains any other private functions that you deem necessary
public class MainApp
a Contains the function
public static void mainString args
Calculates and displays the first N happyprime numbers where N is received from keyboard input. If the user
provides an invalid number for N eg 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
