|
Assignment 1 |
Prerequisite: Before doing this assignment, you will need to install BlueJ and Java. Instructions are on the previous page.
Purpose: This assignment will allow you to try out the BlueJ development environment and learn a little about the structure of Java programs.
import javax.swing.*;
/*
* @author John Rogers
* @course CSC 211
* @project Assignment 1
*
* This program requests two integers and then computes and prints
* their average.
*
*/
public class ComputeAverage {
public static void main(String[] args) {
JOptionPane input = new JOptionPane();
String s1 = input.showInputDialog(null, "Please enter the first number");
String s2 = input.showInputDialog(null, "Please enter the second number");
int number1 = Integer.parseInt(s1);
int number2 = Integer.parseInt(s2);
double average = (number1 + number2) / 2.0;
System.out.println("The average of " + number1 + " and " + number2 + " is " + average);
System.exit(0);
}
}
What to submit: Submit the file ComputeAverage.java through the COL assignment submission page.