Computer Science 523
Advanced Programming

Summer 2014, The College of Saint Rose

ShouldWeSki BlueJ Project

Click here to download a BlueJ project for ShouldWeSki.


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 2366 2014-05-20 02:33:22Z 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...");
        }
    }
}