Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Selsct the correct response: ketone Tiol organic acid aldehyde

Answered: 1 week ago