CS 1401 Assignment #3, Solutions

Date Assigned: Monday, February 5 or Tuesday, February 6, 2007.

Due Date: Monday, February 12, or Tuesday, February 13, 2007, before the beginning of your lab section.

Objective: The main objective of this assignment is to practice graphical input and output and also input, output with files.

Programming assignment: similar to Programming Assignment 2.

Reminder: To protect CS students against snow and cold, the department is thinking of buying warm jackets so that students can keep warm when walking on campus. Jackets come in different size, depending on the student's height. Help the department estimate the cost of these jackets. The cost of a jacket is proportional to the square of the student's height in meters, with a cost of $10 per square meter. Your program should estimate a cost of a jacket for a student. Specifically, your program should:

New features:


import javax.swing.JoptionPane;
import java.io.*;
import java.util.*;

public class WinterJackets
  public static void main(String [] args) throws IOException
    String name;
    int feet;
    int inches;
    int heightInInches;
    double heightInCm;
    double heightInMeters;
    double cost;

    String inputString;
    String outputString;

    name = JOptionPane.showInputDialog("Please enter your name");

    inputString = JOptionPane.showInputDialog
      ("Please enter your height in feet");
    feet = Integer.parseInt(inputString);

    inputString = JOptionPane.showInputDialog
      ("Please enter your height in inches, e.g., 4 or 7");
    inches = Integer.parseInt(inputString);

    heightInInches = inches + 12 * feet;
    heightInCm = 2.54 * heightInInches;
    heightInMeters = heightInCm / 100.0;
    cost = 10.0 * heightInMeters * heightInMeters;

    outputString = "Student name: " + name + "\n" +
      "Umbrella cost: $" + String.format("%.2f", cost);
    JOptionPane.showMessageDialog(null, outputString,
      "UTEP Umbrellas",

    PrintWriter toFile = new PrintWriter("assign03.dat");
    toFile.println("Bill for a UTEP umbrella" + "\n" + outputString);

Homework assignment: on a separate sheet of paper, solve Ex. 10 and Ex. 12, p. 162.

Deliverables: as instructed by your TA.