Vous êtes sur la page 1sur 2

This program is a modified version of Program #1; It uses concepts from chapters

1-3. The program will use dialog boxes in order to ask for the customer's
account number (a 14 digit number), name (first and last), address (street,
city, state, zip) and KWH used (a whole number). It will then calculate the
amount due (KWH * 0.0624).

Output should be printed to a dialog box. Label the account number and amount
due. When printing the address, place the street address on one line and the
city, state and zip on the next line. Attached is an example of a run of the
program.

Begin the assignment by creating a problem analysis and algorithm design as was
done in class with the exam average program. Type the problem analysis and
algorithm design in Word.

Submission: Upload the Word file and main.java file to the dropbox in D2L

Due: Wednesday, October 6 at 4 pm

*Remember to comment your program :)

Give program description of input and output requirements.


Create any formulas needed.
e.x. Average = Sum of Exam Scores [t1 + t2 + t3, ..., tx] / Number of Exams

Algorithm

---
1] Get exam scores from user.
2] Calculate Average.
3] Output Aveage.

Variables
---
Integers for test scores.
int exam1Score
double Average

Named Constant
---
Values that ... ?

int NUM-OF-GRADES

Complete Algorithm
---
1] Ask user for exam 1 score.
2] Get exam1Score.
3] Ask user for exam 2 score.
4] Get exam2Score.
5] Ask user for exam 3 score.
6] Get exam3Score.
7] Calculate Average using formula.
8] Print the Average to screen.

Give program description of input and output requirements.


Create any formulas needed.
e.x. Average = Sum of Exam Scores [t1 + t2 + t3, ..., tx] / Number of Exams

Algorithm
---
1] Get exam scores from user.
2] Calculate Average.
3] Output Aveage.

Variables
---
Integers for test scores.
int exam1Score
double Average

Named Constant
---
Values that ... ?

int NUM-OF-GRADES

Complete Algorithm
---
1] Ask user for exam 1 score.
2] Get exam1Score.
3] Ask user for exam 2 score.
4] Get exam2Score.
5] Ask user for exam 3 score.
6] Get exam3Score.
7] Calculate Average using formula.
8] Print the Average to screen.

Can't use printf with dialog boxes.

String.format (formatSring, ArgumentList);

double examAverage = 75.678

String strexamAverage;

strexamAverage = String.format ("%.2f",examAverage) [Prints double/float to 2


decimal places]

System.out.println ("Your Exam Average is " + strExamAverage);

System.out.println ("Your Exam Average is " + String.format


("%2f"",examAverage))

JOptionPane.showMessageDialog ( null, "Your Exam Average is" + strExamAverage,


"Exam Average",
JOptionPane.INFORMATION_MESSAGE);

Vous aimerez peut-être aussi