Title: JH2 Homework
Course: CPS 161: An Intro to Programming with Java - DL MM MASTER

JH2 Homework(50 points)

Create an Eclipse project named JH2_xxxxx where xxxxx is your NetID. For example: JH2_chasselb. Create the programs described below in this project. Fill in the required fields in the JH2_worksheet.txt file. Insert the JH2_worksheet.txt file at the top level of the project. Export your project file and upload it to blackboard as your work for this assignment.

As you write your code make sure you adhere to the following standards:          Rubric

Make sure you do your Class Participation (5 points)

bounds problem (10 points):

Create a package named bounds and create a program that reads from the Keyboard and prompts the user for 3 numbers:

starting number, upper bound, step size.

Print out the user's input values.

Then write out the sequence of numbers:


starting_number  (starting_number + step_size)  (starting_number+2*step_size)    ...

Continue printing numbers as long as number < upper_bound.

Write out no more than 10 numbers per line.

For example: starting number=2, upper bound=90 and step size=4
should generate the numbers:

2 6 10 14 18 22 26 30 34 38
42 46 50 54 58 62 66 70 74 78
82 86

Run the program with starting number=13, upper bound= 112, step_size=3 and insert the results in the appropriate section of the JH2 worksheet.

temperature problem (10 points):

Create a package named temperature and create a program that has a while loop.

- Inside the while loop, your program will prompt the user for temperature in Centigrade.
- If the Centigrade value read in is <= -100, the loop will exit.
- Otherwise, your program will compute the Fahrenheit equivalent temperature.
- Inside the while loop, your program will print out the Centigrade and Fahrenheit temperatures.
- Keep a count of the valid user inputs and a running total of your Fahrenheit and Centigrade temperatures.
- When the user terminates the while loop, print out the average Centigrade and Fahrenheit temperatures.
- Note that
  - Average_Fahrenheit = Total_of_Fahrenheit/ total_user_inputs
  - Average_Centigrade = Total_of_Centigrade / total_use_inputs
- Also note that:
  - Fahrenheit = (9.0/5.0)*Centigrade + 32.0

***************************************
Here is some sample output from your program:
***************************************
Enter Temp in Centigrade or <= -100.0 to quit:  20
Temperature: F(68.0) C(20.0)
Enter Temp in Centigrade or <= -100.0 to quit:  30
Temperature: F(86.0) C(30.0)
Enter Temp in Centigrade or <= -100.0 to quit:  40
Temperature: F(104.0) C(40.0)
Enter Temp in Centigrade or <= -100.0 to quit:  1
Temperature: F(33.8) C(1.0)
Enter Temp in Centigrade or <= -100.0 to quit:  -10
Temperature: F(14.0) C(-10.0)
Enter Temp in Centigrade or <= -100.0 to quit:  -100

Average: Centigrade(16.2)  Average: Fahrenheit(61.160000000000004)

Run the program with sample inputs shown above and insert the results in the appropriate section of the JH2 worksheet.

alphabet problem (10 points):

Create a package named alphabet and create a program that prints the letters from 'a' to 'z'.

For each letter, display whether the letter is a vowel or a consonant. You can consider 'a', 'e', 'i', 'o', 'u', and 'y' as vowels, everything else is a consonant.

Use a while loop, and a case statement inside of the while loop to generate this program.

HINT:
The numerical values of the characters are in order. This implies that the following code is true:

char letter = 'a';
letter += 1; // letter now has the value 'b'
letter += 1; // letter now has the value 'c'
...

Your output will look something like:

a is a vowel
b is a consonant
c is a consonant
d is a consonant
e is a vowel
f is a consonant
g is a consonant
h is a consonant
i is a vowel
j is a consonant
....

Run the program and insert the results in the appropriate section of the JH2 worksheet.

factorial problem (15 points):

Create a package named factorial and write a program to compute the Factorial Function using a for loop and print out the results. Note that the user can continue computing factorials because you will have an outer while loop which will continue executing as long as the user responds with a 'y' to the "Do you want to continue" question.

The Factorial function is :

Factorial(N) = N * (N-1) * (N-2) .... * 1

Sample output should look like:

Enter in N: 3
Factorial = 6
Do you want to continue? (y/n): y

Enter in N: 4
Factorial = 24
Do you want to continue? (y/n): y

Enter in N: 6
Factorial = 720
Do you want to continue?: (y/n): n

Have a good day

Run your program with the inputs shown above and insert the results in the appropriate section of the JH2 worksheet.

November 22, 2014 11:46 AM