Starting from:
$35

$29

Homework Assignment 1 Solution

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
Input:  3.5 , 4.2
•  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:

•  the sequence of computed values, one per line






Run twice

•  the number of iterations required





Input1:  8   Input 2 19

•  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

Input:

value. Print the following on separate lines:
4.0

•  The number of valid GPAs entered.
3.7

•  The sum of the GPAs
2.9

•  The average GPA
3.5



-1


    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

    • The result of sumInts(M)

    • The value of (M+1)*M / 2

Input:    9




Vers 1.0

More products