Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

ShouldWeSki BlueJ Project

Click here to download a BlueJ project for ShouldWeSki.


Download file: ShouldWeSki.vls


ShouldWeSki Source Code

The Java source code for ShouldWeSki is below. Click on a file name to download it.


ShouldWeSki.java

/*
 * Example ShouldWeSki: ask a couple of questions to determine if it's
 * a good day to ski - to demonstrate a nested if
 *
 * Jim Teresco, The College of Saint Rose, CSC 202, Fall 2012
 *
 * $Id: ShouldWeSki.java 1914 2012-09-25 03:05:03Z terescoj $
 */

import java.util.Scanner;

public class ShouldWeSki {

    public static void main(String[] args) {

        // we will use keyboard input in this one.
        Scanner input = new Scanner(System.in);
           
        // get the temperature
        System.out.print("What's the forecast temperature (F) for tomorrow? ");
        double temperature = input.nextDouble();
        
        // if it's cold or at least cool, maybe we can ski!
        if (temperature < 50.0) {
            // OK, it's cool, but is there enough snow?
            System.out.print("How many inches of snow in the mountains? ");
            double snowCover = input.nextDouble();
            
            // let's say we need 6 inches to be able to ski
            if (snowCover < 6.0) {
                System.out.println("Too bad, " + temperature + " is cool enough, but " 
                    + snowCover + " inches of snow isn't really enough...");
            }
            else {
                System.out.println("Great!  " + temperature + " degrees and " + snowCover +
                    " inches of snow means a day on slopes!");
            }
        }
        else {
           System.out.println("Too bad, " + temperature + " is probably too warm for skiing...");
        }
    }
}