## CS 1401 Assignment #3

Date Assigned: Monday, September 17 or Tuesday, September 18, 2007.

Due Date: Monday, September 24, or Tuesday, September 25, 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 students against rain, the university decided to require every student to purchase a special UTEP umbrella. These umbrellas comes in different size; the cost of an umbrella is proportional to its area in square inches: 1 square inch costs 10 cents, i.e., \$0.10. Umbrellas are of the shape of a half-sphere, so the area can be computed as 2 pi times the umbrella's radius squared. Your program should estimate a cost of an umbrella for a student and generate a bill. Specifically, your program should:

• ask the student for his or her name;
• print a bill with the student's name and the cost of the umbrella.

New features:

• set up dialog boxes for input and output;
• format the input to 2 digits after the decimal points (as is natural in representing dollars and cents);
• in addition to printing the bill on the screen, store it in a file.

```Solution:

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

public class UTEPUmbrellas {
public static void main(String [] args) throws IOException
{
final double PI = 3.141592;
final double costPerSquareInch = 0.1;
String name;
double area;
double cost;

String inputString;
String outputString;

inputString = JOptionPane.showInputDialog

cost = costPerSquareInch * area;

outputString = "Student name: " + name + "\n" +
"Jacket cost: \$" + String.format("%.2f", cost);
JOptionPane.showMessageDialog(null, outputString,
"Winter Jackets",
JOptionPane.INFORMATION_MESSAGE);

PrintWriter toFile = new PrintWriter("assign03.dat");
toFile.println("Bill for a Winter Jacket" + "\n" + outputString);
toFile.close();

System.exit(0);
}
} ```
Homework assignment: on a separate sheet of paper, solve Ex. 10 and Ex. 12, p. 162.

Deliverables: as instructed by your TA.