CSU Banner

CS 163/164, Spring 2018

Programming Assignment - P2

Scientific Formulas

Due Monday, Jan. 29th at 6:00pm

Late - Tuesday, Jan. 30th 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.

Instructions

Write a Java program file called P2.java with a class name P2, 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 Solution
// Author: Russ Wakefield
// Date:   1/21/2017
// Class:  CS163/164
// 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 keyboard = new Scanner(System.in);

        // Prompt and read radius from keyboard
        
        // Calculate circumference, area, and volume

        // Print circumference, area, and volume to console

        // Declare variables for converting mass to energy
        
        // Prompt and read mass from keyboard

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

        // Close scanner
        keyboard.close();
    }
}

Sample Output

Your program should print six lines, including the first, where the user enters the radius, the second, third, and fourth, which print the results of the formulas that compute the circumference, area, and volume. On the fifth line, the user enters the mass, and on the sixth line the result of the energy conversion formula is printed. The user input is shown in blue.

Radius? 1.0
The circumference is 6.28319.
The area is 3.14159.
The volume is 4.18879.
Mass? 1.0
The energy is 89875517873681760.0 joules.

Specifications

Grading Criteria


Submit P2.java to Checkin.


CS Banner
CS Building