Assignment 4
Due Tuesday, April 28 at 11:59pm on Canvas


Pair Programming (Required - Or No Credit)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab code to Canvas.
  • Please make sure both your names are on your file (hint: use a comment).
  • If you need help finding a partner, please contact me as soon as possible.

Assignment 4: Calcuations (10 pts)

  • This worksheet to improve your understanding of how to convert math equations to Java code.
  • For this worksheet, the user enters three numbers. You write code to display the value of the equations listed below using the three inputs.
  • Create a new Java project in Eclipse named Assignment4 and add a new Java class to this folder named Calculations.java.
  • Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
  • Add your and your partner's names and the assignment number to the file in comment block at the top the program.
  • Add a main method, and inside of main, declare a new Scanner variable, and three double variables.
  • Next, prompt the user to enter 3 numbers as shown:
***Math Worksheet***
Enter three numbers, and press the Enter key
Enter the first number here: 1.2
Enter the second number here: 3
Enter the third number here: 4
  • Convert each of the following equations to Java code in your program.
  • Recall that Java allows simple math like we use on a calculator. For expression 1, code the following formula into the program.

x value
 

  • Where a, b, and c are the user input.
  • Next, calculate the gallons of fuel needed to travel b miles where c is the MPG (miles per gallon) of the vehicle. For expression 2, calculate the gallons of fuel needed using the following formula:


fuel equation


  • Where b and c are the user input.
  • An arithmetic mean is the average obtained by dividing the sum of the numbers by their number. The "sum" means to add up a sequence of numbers. For expression 3, calculate the mean of the input using the following formula.

mean equation
 

  • Where a, b and c are the numbers to sum from the user input.
  • An integer part of a decimal number is the part to the left of the decimal point. For expression 4, use the floor() function calculate the integer part of the decimal number a using the following formula.

floor equation

  • Where a is from the user input and ⌊ and ⌋ indicate the floor function in mathematics.
  • The sum of the first n terms of a geometric series is given by the following formula for b ≠ 1:

geo equation


  • where a is the first term, b is the common ratio and c is the number of terms, from the user input.
  • When your program is working a shown in the sample output below, submit Calculations.java to Canvas.
  • Example Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
  1. ***Math Worksheet***
    Enter three numbers, and press the Enter key
    Enter the first number here: 1.2
    Enter the second number here: 3
    Enter the third number here: 4 x = 0.20000000000000018 fuel = 0.75 mean = 2.733333333333333 aInt = 1.0 geo = 48.0
    ***Math Worksheet***
    Enter three numbers, and press the Enter key
    Enter the first number here: 4.3
    Enter the second number here: 2
    Enter the third number here: 1 x = 5.3 fuel = 2.0 mean = 2.433333333333333 aInt = 4.0 geo = 4.3