CSU Banner

CS 150, Fall 2017

Programming Assignment - P2

Scientific Formulas

Due - September 12th, 2017 at 6:00pm

Late - September 13th, 2017 at 8:00am

Objectives of this Assignment

  1. To write a Java program to implement formulas,
  2. to learn how to read input from the user via the console,
  3. to declare variables and use them in expressions, and
  4. to learn about printing formatted output to the console.


Create a Java program called P2 with a class named P2, which after created should contain a file named P2.java in the src folder. An example of the code is shown below. All of the Java code you write should be contained in the main method. For this assignment, you must follow the directions below exactly:

Program Structure

// P2 Assignment 
// Author: Russ Wakefield
// Date:   8/21/2017
// Class:  CS150
// Email:  waker@colostate.edu

import java.util.Scanner;

public class P2 {

    public static void main(String[] args) {

        // Declare variables for geometric formulas

        // Instantiate scanner
        Scanner keyboardInput = new Scanner(System.in);

        // Prompt and read length of triangle and length of cube from keyboard
        // Calculate area and volume

        // Print area and volume to console
	System.out.printf("The triangle area is %.5f.\n", triangleArea);

        // Declare variables for calculating force
        // Prompt and read mass and acceleration from keyboard

        // Compute the force using the formula
        // Print force to console

        // Close scanner
    } // end main
} // end class P2

Sample Output

Your program should print seven lines, including the first and second, where the user enters the two lengths, the third and fourth, which print the results of the formulas that compute the area and volume. On the fifth and sixth lines, the user enters the mass and acceleration, and on the seventh line the result of the force formula is printed. User input is shown in blue.

Length of triangle? 1.0
Length of cube? 1.3
The triangle area is 0.43301.
The cube volume is 2.19700.
Mass? 1.0
Acceleration? 2.25
The force is 2.3 newtons.


Grading Criteria

Submit P2.java to Checkin.

CS Banner
CS Building