CSU Banner

CS 150 - Spring 2018

Lab 3 - Variable and Scanner Introduction, Formatted Printing, and the Start of P2

Wednesday, January 31, 2018


Lab 2 Regrade: If you need a regrade for last week's lab, please open Lab 2 requirements and show one of the TAs your completed work within the first 5 minutes of class. The TAs will not accept regrades after this time.

Objectives of this Lab

  1. Write a Java program that accepts user input,
  2. assigns the input to specific variables, and
  3. learn about printing formatted output to the console.

Starting the Assignment

Instructions

An outline of the code for P2 is shown below. You may copy and paste the comments into your main method if it will help you. 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

// Assignment: P2 
// Author: Russ Wakefield
// Date:   1/31/2018
// Class:  CS150
// Email:  waker@colostate.edu

import java.util.Scanner;

public class P2 {

    public static void main(String[] args) {

        // Declare variables for geometric formula.

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

        // Prompt and read base and height of triangle from keyboard.
        
        // Calculate area.

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

        // Close scanner.
        keyboardInput.close();
    } // end main
} // end class P2

Sample Output

User input is shown in blue.

Base of triangle? 1.23
Height of triangle? 2.34
The triangle area is 1.43910.



© 2018 CS150 Colorado State University. All Rights Reserved.
CS Banner
CS Building