$30
Objectives:
• Become familiar with basic Java program structure
• Become familiar with Java program elements:
o Variable types o Operators and Expressions o Control structures
o Input & Output statements (inc. StdIn, StdOut from the textbook) o Functions
• Be able to use Eclipse to create, debug and run basic Java programs.
• Be able to upload the required files to D2L.
You are to write a Java program for each of the following problems. Name your projects as: csc402hw1a, csc402hw1b, csc402hw1c, csc402hw1d corresponding to problems a-d below.
A) Write a program to prompt the user for 2 floating point numbers, A & B. The program should print, on separate lines:
Input: 3.5 , 4.2
• The sum of the two numbers A + B
• The difference of the two numbers A - B
• The quotient (first/second) A / B
• The quantity: AB, Hint pow( )
B) Write a program to prompt the user for a positive integer, N. The program will repeatedly divide the input in half, discarding any fractional part, until it becomes 1. The program should print on separate lines:
Run twice
Input1: 8 Input 2 19
• the sequence of computed values, one per line
• the number of iterations required
• the value of log2(N)
Input:
4.0
3.7
2.9
3.5
-1
C) Write a program that will prompt the user to enter GPA values one per line, stopping when the user enters a negative value. Print the following on separate lines:
• The number of valid GPAs entered.
• The sum of the GPAs
• The average GPA
D) Write a function with one integer parameter, N. The function will compute and return the sum of the integers from 1 to N. Name the function: sumInts.
Then write a complete program using this function. The main function will prompt the user for an integer, N. The main function will call the sumInts function for every value M from 1 up to N and print out:
• The value M
Input: 9
• The result of sumInts(M)
• The value of (M+1)*M / 2
Vers 1.0