Description
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.
Once you have a program working, run it using the data indicated below, then copy/paste the console output into the top of your java source file in a comment block, right below your name. Upload the .java file to the submission folder.
A) Write a program to prompt the user for 2 floating point numbers, A & B. The program should print, on
separate lines:
- 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( )
Input:
3.5 , 4.2
- 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:
- the sequence of computed values, one per line
- the number of iterations required
- the value of log2(N)
- 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:
• ThevalueM
- The result of sumInts(M)
- The value of (M+1)*M / 2
Input: 9
Run twice
Input1: 8 Input 2 19
Input: 4.0 3.7 2.9 3.5
-1
Vers 1.0