Unit 1 Assignment Instructions
Unit 1 Assignment Instructions
Because this is the first Programming Assignment in the course, the instructions are more detailed
than in later units. You will need to follow the instructions carefully.
https://www.eclipse.org/downloads/packages/release/2019-09/r/eclipse-ide-java-
developers
Once Eclipse is installed, open the Eclipse application. The first time you open it, you will be asked
to select the location for your workspace.
• Click the box for "Use this as the default and do not ask again".
• Click "OK".
• Click the large arrow icon on the right that displays "Workbench" when you move the
mouse over it.
The window should switch to a complicated grid of icons and window panes. Welcome to Eclipse!
The complexity can be intimidating at first, but many professional Java developers find the many
features to be useful.
• The default value should work for everything else. Click "Finish".
A pane on the left side of the Eclipse window should show a folder named "CS1102".
• Click "Finish".
The new file "SuperPower.java" should appear in the center pane for editing. It should have a class
declaration for "SuperPower" with an empty definition block.
Now give your class something to do! Add a "main" method, which will be run as your program.
• Type in the following method definition and output statement inside the definition block of
the class (between the first "{" and last "}").
public static void main(String[] args)
{
System.out.println("SUPER POWERS TO THE RESCUE!");
}
Notice how the editor automatically adds the closing "}" and provides automatic completion as you
type the "System.out.println" call. This automatic completion can be distracting at first, but it is
useful for experienced programmers.
If you make mistakes in typing this method definition, you may see small warning icons to the left
of the lines of code that have problems. For example, if you type "system" instead of "System", a
warning icon will appear left of that line. Move your mouse over the icon to see a message like
"system cannot be resolved".
If you type the method definition correctly, no error icons should appear. Time to run your
program!
• Click the Run icon, a small green circle with a white triangle at the top right of the Eclipse
window.
A dialog box should appear asking if you want to save your resources (your Java code file).
• Click "OK".
The IDE will now compile and run your program. The text "SUPER POWERS TO THE
RESCUE!" should appear in a Console pane at the bottom of the Eclipse window.
But Java was designed for graphical user interfaces (GUIs) more than text output. Change your
program to use some of the built-in graphics features of Java.
• Add the following line at the top of your code, before "public class SuperPower". import
javax.swing.JOptionPane;
This line gives your program access to some built-in dialog boxes.
Make sure you have no warning icons next to any lines of code.
A dialog box should appear with the message "SUPER POWERS TO THE RESCUE!"
• Click "OK".
• Add the following String declaration and initialization just before the existing call to
"JOptionPane.showMessageDialog", inside the definition of the main method. String
power = JOptionPane.showInputDialog("What is your super
power?");
This assignment statement uses the method "showInputDialog", which is a function that returns a
string input by the user. The argument to "showInputDialog" appears in the input dialog prompting
for the input. The String variable "power" is assigned to refer to the String input by the user.
• Change the call to "showMessageDialog" to use the power input by the user.
JOptionPane.showMessageDialog(null,power+" TO THE RESCUE!");
The second argument to "showMessageDialog" is now a String expression. It uses the String
operator "+" to concatenate the contents of the variable "power" with the String literal " TO THE
RESCUE!".
Make sure you have no warning icons next to any lines of code.
A new Input dialog should appear asking for your super power.
• Click "OK".
As a final feature, change the user's input so it is all capital letters. Use the "toUpperCase" method
that is described in Section 2.3.3 of Eck (2019).
Add the following line after the initialization of "power" and before the "showMessageDialog" call
that uses it. power = power.toUpperCase();
The method "toUpperCase" is a function that returns an all-upper-case translation of the String
"power". The assignment with "=" then resets "power" to refer to this modified String instead of the
original.
Congratulations! Now you are ready to submit your assignment. First look up how to take screen
shots on your device. Then run your program again.
• Take a screen shot of this Input dialog box before clicking "OK".
• Click "OK".
• SuperPower.java
• Screen shot showing the Input dialog with some lower-case input.
• Screen shot showing the Message dialog with all upper-case output.