SlideShare a Scribd company logo
1 of 37
10.
USING THE ECLIPSE DEBUGGER
updated: 8/6/18
This tutorial assumes that you have previously completed the
Getting Started with Eclipse tutorial. Since much of what you're
going to do for this tutorial is identical to what you've done for
that tutorial, I will refrain from providing all the details this
time. If you don't remember the details of how to do something,
look it up in the previous tutorial.
This tutorial uses x: to refer to the drive that you're saving your
work to. In the lab, x: should be replaced by the USB drive
(assuming that you're using a USB flash drive storage device).
At home, x: should be replaced by the USB drive or the hard
drive, whichever you prefer.
Whenever you are asked to perform an action (left column
below) that you've already done before, I will refrain from
providing the supplemental information (right column below). If
you don't remember the details of how to do something, look for
it earlier in the tutorial. I expect you to have to look up a lot of
previously covered material. This is my attempt to force you to
memorize how to do things.
Actions
Supplemental Information
Load Eclipse.
Create a project named tutorial2.
In creating a tutorial2 project, Eclipse will 1) create a tutorial2
folder and put it in your workspace folder, and 2) create a
.project file and put it in your tutorial2 folder.
Within your tutorial2 project, create a source code file named
MouseDriver.java and enter this text:
public class MouseDriver
{
public static void main(String[] args)
{
String temp = "stan";
Mouse mickey = new Mouse(temp + "dard", 100, 10);
Mouse fivel = new Mouse("standard", 100, 10);
mickey.printStatus();
mickey.simulateGrowth(4);
mickey.printStatus();
fivel.simulateGrowth(4);
if (mickey.equals(fivel))
{
System.out.println("They're equal");
}
} // end main
} // end class MouseDriver
Save the source file.
Within your tutorial2 project, create a source code file named
Mouse.java and enter this text:
public class Mouse
{
private String variety; // standard, hairless, etc.
private int weight; // the mouse's weight in grams
private int growthRate; // % that mouse grows each day
private int days; // # of simulated days so far
public Mouse(String v, int w, int gR)
{
variety = v; weight = w; growthRate = gR;
} // end Mouse constructor
public void simulateGrowth(int d)
{
days += d;
while ((d > 0) || (weight > 0))
{
weight += growthRate/100 * weight;
d--;
}
} // end simulateGrowth
public void printStatus()
{
System.out.println("After " + days + " days, " +
" weight = " + weight + ".");
} // end printStatus
public boolean equals(Mouse otherMouse)
{
boolean varietyCheck, weightCheck;
varietyCheck = (variety == otherMouse.variety);
weightCheck = (weight == otherMouse.weight);
return varietyCheck && weightCheck;
} // end equals
} // end class Mouse
Save the source file.
Build (i.e., compile) the tutorial2 project.
If necessary, fix compilation errors.
Run the project.
This should appear in the output pane:
After 0 days, weight = 100.
Study the main method to figure out if the output is correct.
Note that the main method contains two calls to the printStatus
method. You may safely assume that the first call to printStatus
was responsible for printing the above status message.
But why doesn't main's second call to printStatus generate a
second status message? The second status message is missing
because, in executing the program, the Java Virtual Machine
(JVM) never reaches the second call to printStatus.
Terminate the program.
Note the red button at the top of your output window. The red
button’s redness indicates that the program is still running. So
why is the program still running? Hmmm ... We'll figure that
out eventually. For now, terminate the program by clicking the
red button. (Makes sense, right? Red for stop.)
As the program terminates, the red button should become non-
red.
Switch to the debug perspective.
Click the Window menu.
Select Perspective / Open Perspective.
Select Debug from the pop-up sub-menu.
That should cause the window's appearance to change to the
debug "perspective."
You should see Debug and Java buttons in the top-right corner
of your window. For practice purposes, click the Java button.
That should cause your window to revert back to its normal
mode, the Java perspective. Click the Debug button to return to
the debug perspective.
Display the MouseDriver.java file.
In your debug perspective, you should see tabs for your
project's source code files in the middle left pane. More
specifically, you should see Mouse.java and MouseDriver.java
tabs. Click the MouseDriver.java tab. Your window should look
approximately like this:
Understand the debug perspective.
Note the five panes in the debug perspective. The top left pane
is called the Debug pane. The Debug pane shows the status of
the currently running program or the status of the just-
completed program. An exit value of 0 means the program
ended normally. An exit value of 1 means the program ended
abnormally.
The top right pane shows two tabbed panes. The Variables pane
shows the current state of program variables while the program
is running. The Breakpoints pane shows the status of
breakpoints within the program. A breakpoint is a marker. When
the debugger reaches a breakpoint marker, it stops executing the
program and waits for the user's next instruction.
The middle right pane is the Outline pane. It shows the instance
variables and methods for the source code file that's currently
chosen in the middle left pane.
The bottom pane shows two tabbed panes – Console and Tasks.
The Console pane shows the console-based output generated by
the program and the input entered by the user.
Set a breakpoint.
In debug mode, you'll need to specify one or more lines in your
program as breakpoints so that when you run your program, the
debugger will stop at the breakpoints. If you don't set a
breakpoint, then when you run your program, the debugger will
run the same as it ran in non-debug mode.
Click your mouse on the first executable line in your
MouseDriver.java source code (click on the String temp =
"stan"; line).
Click the Run menu.
Note the Toggle Breakpoint option. At the right of the Toggle
Breakpoint option, you should see Ctrl+Shift+B. That's a hotkey
shortcut. Ctrl+Shift+B means that to set a breakpoint, you can
hold down the Ctrl and Shift keys and then tap the b key (b for
break). This time, don't use the hotkey shortcut; instead click on
the Run menu's Toggle Breakpoint option.
After setting the breakpoint, you should see a bullet in the gray
area at the left of the breakpoint line. For practice purposes,
press Ctrl+Shift+B and notice how the bullet disappears. Press
Ctrl+Shift+B again and notice how the bullet reappears.
Initiate a debug session
Click the Run menu.
Select Debug As.
Select Java Application from the pop-up sub-menu.
That should cause the debugger to run to the first breakpoint
line. The first executable line (String temp = "stan";) should be
highlighted.
Examine the Step Over option.
Click the Run menu.
Note the Step Over option. If your Step Over option (and other
debug options) are grayed out, that means they are deactivated
and unusable. If that’s the case, then you might have external
software that’s hindering your debug session. On my home
computer, my McAfee software prompted me with “Do you want
to allow javaw.exe to access the Internet?” When I clicked
“Allow,” my Eclipse debug options became active.
Understand different techniques for stepping over a line of
code.
At left of the Run menu’s Step Over option, you should see an
icon with an underscore and an arrow jumping over it. At the
right of the Step Over option, you should see the hotkey
shortcut, F6. Those labels indicate alternative shortcut ways to
select the Step Over option. To use that shortcut, you can click
on the same-looking button above the Debug pane. To use F6,
you can simply press the F6 key. Of course, as a third
alternative, you can click on the Run menu's Step Over option.
Back out of the Run menu by pressing the Esc key.
Step over two lines of code.
Now initiate two step-over actions by 1) clicking the icon with
the arrow jumping over the underscore and then 2) pressing F6.
Step into the code.
Notice that the step-over action causes the debugger to jump to
the line that's positioned immediately below the current line in
the program. Sometimes you won't want to jump there. Instead
you'll want to jump inside of the method or constructor that the
current line is calling.
The debugger should now be highlighting the line that
instantiates the second Mouse object. With the first
instantiation line, you performed a step-over command. This
time, we want you to perform a step-into command so that you
can see what happens when the Mouse object is created.
Click the Run menu.
Click Step Into (as always, feel free to use the alternative
shortcut methods as specified by the labels on the Step Into
option).
The step-into action causes the debugger to jump into the
module (constructor or method) that the current line is on. In
this case, the module is a constructor. Notice how the
constructor assigns the three passed in argument values to the
three instance variables.
Step until printStatus is highlighted.
Perform the step-over action several times and that should take
you through and then out of the Mouse constructor. Perform the
step-over action until the printStatus line is highlighted.
Step into the printStatus method.
Perform the step-into action to jump into the printStatus
method. Perform the step-into action again while the
System.out.println line is highlighted.
Practice stepping into and out of an api method.
Normally, you won’t want to step into an API method
(System.out.println is an API method) because there's no need
to debug API methods. However, sometimes you'll step into a
method accidentally. To step out of a method, click the Run
menu and then select the Step Return option. Perform the step-
return action so that the System.out.println line is once again
highlighted. Perform the stepover action several times until the
mickey.simulateGrowth(4) line is highlighted.
Step into the simulateGrowth method.
View the values for the simulateGrowth method's variables.
While inside the simulateGrowth method, view the Variables
pane (click the Variables pane's tab if necessary). In the
Variables pane, you should see the d parameter and the this
reference.
The d parameter should display the value 4.
Click the this reference's expansion icon (a triangle) to display
the calling object's instance variables.
The weight variable should display a value of 100 and the
growthRate variable should display a value of 10.
Step through the simulateGrowth method.
Perform a number of step-over actions and observe how the d
variable decrements correctly and observe how the weight
variable does not behave correctly (it does not change its value
at all).
Why does weight's value not change?
Inspect expression values.
Highlight the growthRate/100 * weight expression and then
right click. Select Inspect from the pop-up menu.
Note that the Inspect feature allows you to evaluate an entire
expression (whereas the Variables pane only displays values for
individual variables).
Note that the expression's value is 0.
Why?
Close the Inspect window by clicking anywhere outside of the
inspection box.
Highlight the growthRate/100expression and inspect its value.
Note that the expression's value is 0.
Why?
Integer division!
Find the declaration for the growthRate instance variable.
Note that it's declared as an int.
10 / 100 does indeed evaluate to 0.
What's the solution?
Fix the bug.
Terminate the program by clicking the red button in the Debug
pane or the red button in the Console pane.
Edit the growthRate declaration so that it's declared as a double
instead of an int.
Run the project in normal mode.
Although you're using the debug perspective, it's possible to run
your program in normal mode, with debugging turned off.
To run a program, you need to select the source code pane for
the class that contains main, so click the MouseDriver.java tab.
Click the Run menu.
Select Run As.
Select Java Application from the pop-up sub-menu.
The program, unfortunately, produces the same results as before
– one line of output from the printStatus method and no
program termination. Don’t get mad and assume that your fix
from before didn't help. Instead, realize that you have additional
bugs to fix. Please remember that patience is a virtue in the
programming profession!
Terminate the program.
Set a breakpoint in the simulateGrowth method.
This time, instead of stepping all the way through the program
until we get to simulateGrowth's loop, let's take a shortcut by
setting a breakpoint within the loop and then running the
program up to that breakpoint.
Before adding the new breakpoint, let's remove the old
breakpoint.
Select the Breakpoints pane. Look for the Remove All
Breakpoints button (the button with the two X's on it) and click
it.
In the Mouse pane, scroll to the while loop in the
simulateGrowth method.
Add a breakpoint to the weight += … line.
Initiate a debug session.
If you want to use the Run menu to initiate your debug session,
you first have to select the MouseDriver.java pane.
As a shortcut alternative to using the Run menu, feel free to use
the debug button at the top of the window. It's the button with
the bug picture on it. In clicking the button, it runs the program
that was previously run. Since you previously ran the
MouseDriver program, the debug button should work fine.
Hover your mouse over the debug button.
That should cause the microhelp text "Debug MouseDriver" to
pop up.
Click the button in order to run your MouseDriver program in
debug mode.
The debugger should execute your program up to the breakpoint
line. The debugger's current line (as indicated by an arrow at
the left of the line) should now be on the weight += … line.
Run to the next breakpoint.
Click the Run menu.
Select Resume.
The debugger should run through the loop one time and stop at
the weight += line once again. Select the Variables pane and
note that the d and weight values are updated appropriately.
Run to the next breakpoint four more times in succession.
Note that the d value decrements past zero and becomes a
negative number. The loop was supposed to terminate when d
reached zero. What's the bug?
Fix the bug.
Terminate the program.
Change the while loop's condition so that it uses && instead of
||.
Run project in normal mode.
This time, the program should terminate successfully and both
printStatus method calls should generate reasonable output.
Since the main method initializes both Mouse objects with the
same values, we'd expect the "They're equal" message to be
printed.
Why is it not printed? Apparently the equals method returned a
false instead of a true. But why?
Initiate a debug session.
The debugger should execute the program up to the
simulateGrowth breakpoint line.
Remove the breakpoint in simulateGrowth.
Find the breakpoint line in simulateGrowth. Click on the
breakpoint line and then press Ctrl+Shift+B.
The reason that we had you remove the breakpoint in
simulateGrowth is because we're no longer interested in tracing
through the simulateGrowth method. Instead, we're interested in
tracing through the equals method.
Set a breakpoint in the equals method.
Note that breakpoints can only be set on executable lines of
code.
Method headings are not considered to be executable lines of
code.
This line is the first executable line of code in the equals
method:
varietyCheck = (variety == otherMouse.variety);
Set a breakpoint on that line.
Initiate a debug session.
The debugger should execute the program up to the equals
breakpoint line.
View the values for the equals method's variables.
While inside the equals method, view the Variables pane (click
the Variables pane's tab if necessary). In the Variables pane,
you should see the this reference and the otherMouse reference.
Since they're both reference variables, they should have
expansion icons at their left. Click the expansion icons to reveal
the values of their instance variables.
Inside a method, a calling object's instance variables are often
written without a "reference variable dot" prefix. Thus, the
variables that appear to the left of the "==" operators (variety,
weight, and growthRate) are the calling object's instance
variables.
The Variables pane shows that the calling object's variety,
weight, and growthRate instance variable values are the same as
the otherMouse's variety, weight, and growthRate instance
variable values. So why didn't the equals method return a true
when we previously ran the program?
For this bug, the Variables pane is actually not all that helpful.
It looks like the instance variable values are all the same, but
are they really ... ?
Step over the varietyCheck assignment statement.
Inspect the varietyCheck variable.
In the Inspect window, varietyCheck's value is false. Why?
Remember that variety is a String and a String is a reference
variable and a reference variable holds an address. The address
stored in mickey's variety instance variable is different from the
address stored in fivel's variety instance variable. Thus, the ==
operator yields a value of false.
What's the solution?
Fix the bug.
Terminate the program.
Change the variety's test for equality so that it uses .equals
instead of ==.
Run the project in normal mode.
This time, the program should generate reasonable output for
the two printStatus method calls and it should print "They're
equal".
Exit from Eclipse.
11.
GETTING STARTED WITH ECLIPSE
updated: 8/6/18
OBTAINING AND INSTALLING ECLIPSE FOR YOUR HOME
COMPUTER:
Since Eclipse is installed in the lab, obtaining it for your home
computer is recommended, but not required.
I couldn't find an official listing of Eclipse's system
requirements. The following specifications are cobbled together
from various sites that use Eclipse:
· 512 MB RAM minimum (1 GB RAM recommended)
· 1 GB hard disk space minimum
If your home computer meets the system requirements and you'd
like Eclipse for home usage, then read the rest of this section.
Otherwise, jump to the next section.
Eclipse is an Integrated Development Environment (IDE) that
allows you to enter, compile, and run programs. The programs
can be written in one of many different languages. In order to
make a particular language work in Eclipse, the language's
compiler must be installed. The compiler installation is separate
from Eclipse's installation.
To obtain the Java compiler, go to this website:
http://www.oracle.com/technetwork/java/javase/downloads
On that website, you'll see various options for downloading the
Java Standard Edition (SE) software. Feel free to read about all
the download options and download the ones you want, but the
only one you'll really need is the most recent Java SE 10 JDK
download option (JDK stands for Java Development Kit). Click
the associated JDK Download link. Using the website's prompts
as a guide, you might have to follow a series of instructions and
links in order to find the JDK download link that matches your
particular operating system. Click on that link and save the file
by downloading it to your computer.
After the download completes, install the JDK as directed.
During the installation process, you will be given the
opportunity to select different setup options. I accept the
default, which is to install everything, but if you want to save
space, you should be able to deselect the Source Code, Public
JRE, and Java DB setup options.
To obtain Eclipse, go to this website:
http://www.eclipse.org/downloads
Click on the Download button under the Get Eclipse heading
and follow the instructions.
After the download completes, install Eclipse as directed. From
the menu of installation options, click on the Eclipse IDE for
Java Developers option (not the Eclipse IDE for Java EE
Developers option). That should generate an installation
window. Feel free to accept the default installation folder. For
me, the default installation folder was C:UsersJohnjava-
oxygen, which I don’t like, so I used File Explorer to create a
new folder named “eclipse Photon” and then I entered
“c:eclipse Photon” in the installation folder field (I tried to use
my hard drive’s root folder and my Program Files folder, but
neither of those folders worked due to permissions problems).
You can accept your default installation folder or try getting a
different folder to work. You should see checkboxes for Create
start menu entry and Create desktop shortcut, and those boxes
should be selected. Click the Install button. After the
installation completes, close the installation window.
SAVING FILES:
· Naturally, you are required to save your program files. In the
lab, you are required to save your files on a USB flash drive
storage device. If you're working at home, you may save your
save your files on your computer's hard disk, but you're still
required to have a flash drive so that you can transport your
files to and from school. If you're at the school's lab, do not use
the hard disks ever!
TUTORIAL:
When working on homework assignments, use Eclipse to enter,
debug, and run your programs. If you forget how to do
something in Eclipse, it is up to you to carefully reread this
Eclipse tutorial and figure out how to do things. To reduce the
number of rereads, go through this tutorial slowly and try to
remember what you're doing.
This tutorial uses x: to refer to the drive that you're saving your
work on. In the lab, x: should be replaced by the USB drive
(assuming that you're using a USB flash drive storage device).
At home, x: should be replaced by the USB drive or the hard
drive, whichever you prefer.
Whenever you are asked to perform an action (left column
below) that you've done before, I will refrain from providing
the supplemental information (right column below). If you don't
remember the details of how to do something, look for it earlier
in the tutorial. I expect you to have to look up a lot of
previously covered material. This is my attempt to force you to
start memorizing how to do things.
Actions
Supplemental Information
Start Eclipse.
Click on the Start menu.
Click on Eclipse.
Create a workspace.
Clicking Eclipse (above) should cause a Workspace Launcher
dialog to appear.
In the Workspace box, enter x:219pgms.
Since this is the first time you've specified x:219pgms in the
workspace box, you'll be creating a new workspace – the
219pgms workspace. The 219pgms workspace is contained in
the 219pgms folder. If the 219pgms folder doesn't exist, Eclipse
will create it for you automatically.
Make sure the "Use this as a default and do not ask again" box
is unchecked.
Click OK.
Clicking OK should cause Eclipse to create the 219pgms
workspace and load a Welcome screen.
Go to the workbench.
It's not required, but feel free to explore the Welcome screen's
links.
The workbench is the area where you'll do all your work –
where you'll enter, debug, and run code. To close the Welcome
screen and go to the workbench, click on the screen’s
Workbench button in the top-right corner.
If there was no prompt for workspace.
If you ever load Eclipse and the Workspace Launcher dialog
doesn't appear, that means someone checked the "Use this as a
default and do not ask again" box. That's a bad thing
(particularly in the lab) because then all users are taken to the
same workspace location and that location might be
inappropriate. To correct this problem, perform these steps after
getting to the Eclipse workbench:
Click the Window menu.
Select Preferences.
That should cause a Preferences window to appear.
In the container tree at the left of the Preferences window,
expand the General container by pressing the symbol at its left.
Expand the Startup and Shutdown container, and inside the
container, select the Workspaces option.
Make sure the "Prompt for workspace on startup" box is
checked.
Click Apply and Close.
Make sure you’re using the Java perspective.
Eclipse can be used for many different languages. If the
previous Eclipse user used it for a language other than Java,
switch the Eclipse perspective back to Java.
In the top-right corner of your workspace window, you should
see icons for the perspectives that Eclipse has used in the past.
You should see a Java perspective icon (look for a J), and it
should be selected. If it’s not selected, select it. If you want to
select it, but can’t see it as a selection option, select Window /
Open Perspective / Other… In the Open Perspective dialog,
select Java and then click Open.
Make sure your Java JDK and JRE settings are correct.
Click the Window menu.
Select Preferences.
That should cause a Preferences window to appear.
In the container tree at the left of the Preferences window,
expand the Java container by pressing the symbol at its left.
Select the Compiler option, which should generate a Compiler
frame.
In the Compiler compliance level field, make sure the Java
version that you just installed is selected.
In the Java container at the left, select the Installed JREs
option. In the Installed JREs frame, make sure the Java version
that you just installed is selected. If it’s not displayed as an
option to select, use the Add button to search for it and add it.
Click Apply and Close.
How to set coding-style preferences.
You'll now set Eclipse's coding-style preferences so they match
the ICS Program’s coding-style conventions.
Select Window / Preferences.
That should cause a Preferences window to appear.
In the container tree at the left of the Preferences window,
expand the Java container and then the Code Style sub-
container.
Select the Formatter option.
In the Active profile box, make sure that Java Conventions is
selected.
Click the Edit… button.
That should cause a Profile window to appear.
In the Profile window, click the Indentation tab.
In the Tab policy drop-down box, select Spaces only.
In the Indentation size box, enter 2.
In the Tab size box, enter 2.
Make sure that the Align fields in columns box is unchecked.
Make sure all the boxes in the Indent section are checked,
except for the Empty lines box.
Click the Braces tab at the top of the Profile window.
For all the boxes except the array initializer box, make sure that
Next line is selected.
For the array initializer box, make sure that Same line is
selected.
Click the White Space tab at the top of the Profile window.
Expand the Arrays container.
Select the Array initializers option.
Make sure that the after opening brace and before closing brace
boxes are unchecked.
The rest of the default code-style formatter profile closely
matches the ICS Program’s coding-style conventions, so there's
no need for any more adjustments to it.
In the Profile name box at the top of the Profile window, type
ICS Program.
Click OK.
How to set default build path for new Java projects.
To keep things simple, you should store your source-code files
and your bytecode files in the same folder as the project’s root
folder. This step specifies that policy as your default.
In the Preferences window’s expanded Java container, select the
Build Path container.
In the Build Path frame, select the Project option.
Click Apply and Close to close the Preferences window.
How to export preferences.
I recommend that you put all of your homework into the same
workspace. That way you can share your workspace's coding-
style preferences. Nonetheless, there will probably come a time
when you'll want to create a new workspace. When you do so, I
recommend that you export your original workspace's coding-
style preferences to an external file and then import that file
into your new workspace. Here's how to export:
Select File / Export….
That should cause an Export window to appear.
In the container tree at the left of the Export window, expand
the General container.
Select the Preferences option.
Click Next.
That should cause an Export Preferences window to appear.
Make sure the Export all box is checked.
In the To preference file box, select the folder and file where
you want to store your preferences file (I selected x:eclipse
oxygen) and followed by the filename ICS_Profile. Click
Finish. Note that a .epf extension is appended to the filename by
default.
If you'd like to test that your export worked, shut down Eclipse,
open up a new workspace, and attempt to import the
ICS_Profile.epf file.
What is a project?
A project is an entity that helps to organize all the files in a
particular program. A project's settings are stored in a .project
file. The .project file is contained in the project's folder.
How to organize your projects.
I recommend that you use one workspace to store all your CS
219 projects. In this tutorial, you've already created a 219pgms
workspace and you will create a tutorial project within that
workspace. The 219pgms workspace uses a 219pgms folder. The
tutorial project will use a tutorial folder which is a subfolder of
219pgms. For your homework assignments, I recommend that
you create hw1, hw2, etc. projects within the 219pgms
workspace.
Create a project.
Select File / New.
In the pop-up submenu, select Project….
That should cause a New Project window to appear.
In the New Project window’s container tree, expand the Java
container and then select the Java Project option.
Click on the Next button.
That should cause a New Java Project window to appear.
If someone has previously created an Eclipse Java project
(which would be the case if you are in the lab), then, as a
shortcut alternative to selecting Project… / New Project, you
can select Project… / New Java Project , and that should cause a
New Java Project window to appear immediately.
In the Project name box, enter tutorial.
Verify that in the Project layout area, “Use project folder as
root for sources and class files” is selected.
Click the Next button.
Click the Finish button.
Verify project creation.
Go to File Explorer and locate the x:219pgmstutorial folder.
Verify the existence of the .project file within the tutorial
folder. If you don't see the tutorial folder, try double clicking
on the 219pgms folder.
Find Package Explorer.
At the left of your Eclipse window, you should see a Package
Explorer pane that contains your workspace's project folders. If
the package explorer pane is not shown, open it as follows:
Select Window / Show View.
Select the Package Explorer option.
Create a source code file.
In the Package Explorer frame, right click on the tutorial
project.
Select New from the pop-up menu.
Select File from the pop-up submenu.
That should cause a New File window to appear.
In the New File window, select the tutorial folder.
In the File name box, enter Hello.java.
Click the Finish button.
That should cause an empty Hello.java frame to appear in the
workbench.
Enter this text:
Enter this text in the Hello.java frame such that <your name> is
replaced with your actual name.
/****************************************
* Hello.java
* <your name>
*
* This program says "hello" to the world.
****************************************/
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello world!");
} // end main
} // end class Hello
Understand the code.
The top section is known as the prologue section. It provides
documentation for human readers. The compiler ignores
everything between the opening /* and the closing */.
main methods should be enclosed in a class that is public and
whose name matches the name of the enclosing file. For
example, the main method above is enclosed in a public class
named Hello. The class must be named Hello since the
enclosing file is named Hello.java.
Save the source file.
Click on the save icon (the save icon looks like a diskette).
Compile your program.
Click the Project menu.
If the Build Automatically option is checked, click it (so that it
becomes unchecked). Click the Project menu.
Select the Build All option or the Build Project option.
If necessary, fix compilation errors.
Click the Problems tab at the bottom of the workbench window.
There should be no errors in the Problems frame, but if you
entered something incorrectly and there are errors, fix them.
Run the program.
Make sure that the cursor is somewhere within your program’s
source code.
Click the Run menu.
Select the Run option.
That should cause a progress-bar dialog box to appear (with a
fast computer, you won’t be able to see it). The progress bar
indicates that a main method is being searched for. The default
place to find the main method is in the workbench's current
class (i.e., the class that's currently displayed). For the current
case, the main method is found in the Hello class.
After the progress-bar dialog box disappears, the Console tab
should appear in the bottom of the workbench window.
Click on the Console tab.
That should cause Hello world! to appear in the Console frame.
If necessary, fix runtime errors.
Create a second program.
To create a new program, you can of course enter it from
scratch as you did for the Hello.java program. As a shortcut,
this time we'll copy from an existing program and edit the copy.
Find your program in the Package Explorer pane.
In the Package Explorer pane, look for the tutorial container and
expand it by pressing the symbol at its left.
In the tutorial container, look for the (default package)
container and expand it.
Look for your Hello.java file inside the default package
container.
Copy your program.
Right click on your Hello.java file.
In the pop-up menu, select Copy.
Right click on the tutorial project.
In the pop-up menu, select Paste.
That should cause a Name Conflict dialog to appear.
In the new name box, enter Countdown (no need to enter the
.java extension).
Click OK.
That should cause a Countdown.java file to appear in the
tutorial project.
Open the Countdown.java file.
Double click on the Countdown.java file.
Edit the Countdown.java file.
Edit the Countdown.java file so that it contains this:
/****************************************************
* Countdown.java
* <your name>
*
* This program prints a countdown from a user-entered
* starting position.
****************************************************/
import java.util.Scanner;
public class Countdown
{
public static void main(String[] args)
{
int startPos; // starting position for countdown
Scanner stdIn = new Scanner(System.in);
System.out.print("Enter countdown starting position: ");
startPos = stdIn.nextInt();
for (int i=startPos; i>0;)
{
System.out.println(i + "...");
}
System.out.println("Lift off!");
} // end main
} // end class Countdown
Ignore resource leak.
If you see a warning for the stdIn initialization statement, you
can ignore it. If you want an explanation, see
http://www.coderanch.com/t/590921/java/java/Scanner-
Resource-leak.
Save the Countdown.java source file.
Compile your program.
Note that the build commands compile more than just the one
file that's displayed in the source-code frame. The Build All
command compiles all the files in your workspace and the Build
Project command compiles all the files within your project. At
this point, there's only one project in your workspace, so both
build commands compile the same files - Hello.java and
Countdown.java.
If necessary, fix compilation errors.
Run the program using the run icon.
As a shortcut alternative to using the Run menu, this time, run
your program using the run icon. More specifically, look at the
top of the workbench for a green-circle icon with a white
triangular arrow inside it.
Hover your mouse over the icon.
That should cause the message Run Countdown to pop up.
Click the icon in order to run your Countdown program.
Open the Console frame.
You should see a prompt to enter the countdown starting
position. To move your cursor to the prompt area, click within
the Console frame. Enter 30.
After pressing enter, your Console frame should be filled with
multiple lines of 30...
Why is your Console frame filled with multiple lines of 30... ?
Terminate the program.
Your program is repeatedly printing the line 30...
That's an example of an infinite loop.
Note the red button at the upper-right corner of your Console
frame. The red button allows the user to terminate a program
that's currently running. (Makes sense, right? Red for stop.)
To stop the infinite loop, click the red button.
As the program terminates, the red button should become non-
red.
Find the error.
An infinite loop is an example of a run-time error.
Run-time errors are often more difficult to debug than
compilation errors because you do not have the benefit of a
compiler-generated error message.
Can you figure out the error?
Do not continue until you attempt to find the error.
Fix the error and recompile.
That's right, the for loop heading is missing its third component.
Replace the for loop heading with this line:
for (int i=startPos; i>0; i--)
Save Countdown.java and recompile.
Run the program.
After initiating the run process, you should be prompted to enter
the countdown starting position.
Enter 30.
Your Console frame should display this:
Enter countdown starting position: 30
30 ...
29 ...
<28 through 2 go here>
1 ...
Lift off!
Note that you'll probably need to scroll up and down to see the
entire output.
If necessary, fix errors.
Copy the program's output into a Word document.
Next, you'll learn how to copy your program's output into a
Word document. You'll need to do this for every homework
project.
Use your mouse to select the output (in the Console frame).
Press Ctrl+c to copy the selected text.
Your output is now copied to your computer's buffer. You'll
next need to paste it into a Word document. Open a new Word
document. To paste the previously copied text into the Word
document, make sure your cursor is within the Word document
and then press Ctrl+v.
Save the Word document in a file named tutorial.docx.
Copy the program's source code into a Word document.
Make sure your cursor is in the Eclipse source code window.
Press Ctrl+a to highlight your entire program. Press Ctrl+c to
copy the highlighted text. Go to your tutorial.docx Word
document. Insert your cursor just prior to your output. Press
Ctrl+v to paste your source code just prior to your output. Press
the Enter key several times in order to separate your source
code from your output.
Apply monospace font to your source code.
For every homework project, you're required to use monospace
font for your project source code and project output. Font refers
to the appearance of characters. Monospace fonts are fonts such
that each character is the same width. Using monospace font
ensures that text that's supposed to be aligned stays aligned
when it's printed. In your homework projects, if your source
code or output is not aligned properly, you will lose style
points.
To apply monospace font to your Word document's source code,
drag your mouse across the source code so that it becomes
highlighted. Use Word’s font name scroll bar to search for
Courier New (a popular monospace font), select it, and click OK
to apply your font selection.
Apply monospace font to your output.
Save your Word document and Exit from Word.
Exit from Eclipse.
Click the X in the top-right corner or select Exit from the File
menu.
Start Eclipse
This time when you start Eclipse, the Workspace Launcher
dialog should display x:219pgms as the suggested workspace.
Click OK.
That should cause Eclipse to load your 219pgms workspace and
your tutorial project.
If the workspace launcher doesn't work.
I've found that I'm occasionally unable to reload a workspace. If
that happens, use File Explorer to delete the workspace's
.metadata folder. Then (re)create your workspace as described
above.
Exit from Eclipse.
CS 219 - HOMEWORK 1
due: Thu, 8/23/18
HOMEWORK SUBMISSION POLICIES:
· Put all of your work, even project source code and project
output, into a single homework document, and submit that
document to the course website by midnight of the day that the
homework is due. Put your name at the top of that document.
· Make sure that the problems in your homework document are
in the same order as the problems in the homework assignment.
· In your homework document, make sure that you use
monospace font for your project source code and project output.
The monospace font ensures that text that's supposed to be
aligned stays aligned when it's printed. If your printed source
code is not aligned properly, you will lose style points. To
achieve monospace font, highlight the relevant text, right click,
and select Font. In the Font window, search for Courier New,
select it, and click OK to apply your font selection.
MANDATORY UNGRADED WORK:
Read my Getting Started with Eclipse tutorial. As you read the
tutorial, perform the steps as described in the tutorial. If you
haven't done so already, print my Homework Assignment
Guidelines – Java Programming document and my Java Coding
Conventions Guidelines document. You must follow the
guidelines found in those documents. Read the documents now!
PRACTICE PROJECT (Do not submit an answer because the
answer will be provided):
Provide a complete program that handles the processing of
Rectangle objects. Your Rectangle class should contain:
· two instance variables, height and width, that keep track of a
rectangle's dimensions
· a static variable, numOfRectangles, that keeps track of the
total number of instantiated rectangles
· A 0-parameter constructor
· A constructor that receives two parameters, height and width
· getNumOfRectangles – a method that retrieves the number of
instantiated rectangles
· addHeight – a method that receive an int parameter and adds
the parameter's value to the height variable (Note: The
addHeight method must be implemented so as to enable method
call chaining.)
· addWidth – a method that receive an int parameter and adds
the parameter's value to the width variable (Note: The addWidth
method must be implemented so as to enable method-call
chaining.)
· printArea – a method that print's the rectangle's area
Write your code such that the following main method would
produce the output shown below.
public static void main(String[] args)
{
Rectangle r1 = new Rectangle();
r1.printArea();
Rectangle r2 = new Rectangle(2, 4);
r2.printArea();
r2.addHeight(3).addWidth(3);
r2.printArea();
System.out.println(
"Total number of rectangles = " +
Rectangle.getNumOfRectangles());
} // end main
Output:
Rectangle's area = 0
Rectangle's area = 8
Rectangle's area = 35
Total number of rectangles = 2
As always, your program should mimic the output format
precisely.
Submit answers for all of the following questions.
EXERCISES:
The following exercise questions refer to material in the Getting
Started with Eclipse tutorial.
1. In Eclipse, what is the name of the file that stores a project's
settings? (The project-settings file is different from the file that
stores coding-style preferences.)
2. What button should you click to terminate the currently
running program?
3. When you print your output, why is it important to use
monospace font for your program output and program source
code?
PROJECT:
Provide a complete program that stores scores for individual
exams and calculates the average score and grade for all exams
combined. Specifically, provide an ExamScore class that
contains these attributes:
· Named constants for the letter grade minimum cutoff values.
Use A = 0.9, B = 0.8, C = 0.7, and D = 0.6. Generate an F for a
score less than .6
· The number of exams.
· The maximum number of points possible on each exam (every
exam has the same number of maximum points, so use a
variable that’s shared between all the objects).
· The total points earned on all exams combined.
· The points earned on a particular exam.
For each of your variables, think about whether it should be a
named constant, a class variable, an instance variable, or a local
variable. As always, use the most appropriate kind of variable
for the variable’s intended purpose.
You are welcome to provide additional constructors and
methods, but at a minimum, your ExamScore class should
implement these constructors and methods:
· 1-parameter constructor –Assign a passed-in earned points
value to the exam object’s earnedPoints attribute. Update the
total number of exams and the total earned points for all exams
combined.
· setMaxPointsForEachExam – A standard mutator method for
the maxPointsForEachExam variable.
· printScore – Print the calling object exam’s score and letter
grade. For additional details, see the output, below.
· printCombinedScore – Print the score and letter grade for all
grades combined. For additional details, see the output, below.
Use appropriate modifiers for methods. The modifiers we’ve
discussed so far are private, public, and static. You are required
to use a helper method if it is appropriate to do so.
Provide a main driver method. It should:
· Call setMaxPointsForEachExam such that 100 is assigned as
the maximum score for each exam.
· Instantiate four ExamScore objects and store them in the
variables exam1, exam2, exam3, and exam4. In the
instantiations, initialize the objects to these values:
exam1: 70.5 earned points
exam2: 90 earned points
exam3: 79.5 earned points
exam4: 78 earned points
· For exam1, exam2, and exam3 (but not exam4), call
printScore.
· Call printCombinedScore.
Output, using the main driver method described above:
On this exam, you earned 70.5 out of 100.0 possible points: C
On this exam, you earned 90.0 out of 100.0 possible points: A
On this exam, you earned 79.5 out of 100.0 possible points: C
On all exams combined, you earned 318.0 out of 400.0 possible
points: C
As always, your program should mimic the output format
precisely.
EXTRA CREDIT (2 pts):
Add functionality to your ExamScore class such that it can
calculate the average score and grade with the lowest exam
score thrown out. If you call your new
printCombinedScoreWithLowestRemoved method after
instantiating four exams as described above, your program
should display this:
With your lowest exam thrown out, you earned 247.5 out of
300.0 possible points: B
Your printCombinedScoreWithLowestRemoved method should
not permanently remove the lowest score. So the output from
printCombinedScore should be the same regardless of whether
you call it before or after you call
printCombinedScoreWithLowestRemoved.

More Related Content

Similar to 10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx

LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxDIPESH30
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Abhishek Khune
 
ArduinoWorkshop2.pdf
ArduinoWorkshop2.pdfArduinoWorkshop2.pdf
ArduinoWorkshop2.pdfPedramKashiani
 
Promethean ActivInspire IWB Introduction
Promethean ActivInspire IWB IntroductionPromethean ActivInspire IWB Introduction
Promethean ActivInspire IWB IntroductionChristyBusch
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java AppletsTareq Hasan
 
controlling_animations
controlling_animationscontrolling_animations
controlling_animationstutorialsruby
 
controlling_animations
controlling_animationscontrolling_animations
controlling_animationstutorialsruby
 
Coding io1--materials for students-group6
Coding io1--materials for students-group6Coding io1--materials for students-group6
Coding io1--materials for students-group6Georgeta Manafu
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculatorVlad Kolesnyk
 
Darkroom 2 photoshop masking techniques and smart objects
Darkroom 2 photoshop masking techniques and smart objectsDarkroom 2 photoshop masking techniques and smart objects
Darkroom 2 photoshop masking techniques and smart objectsdaviddiener
 
Eclipse Pocket T I P Sn T R I C K S
Eclipse Pocket  T I P Sn T R I C K SEclipse Pocket  T I P Sn T R I C K S
Eclipse Pocket T I P Sn T R I C K Sguestd8c458
 
Introduction To Windows Xp Class 1
Introduction To Windows Xp   Class 1Introduction To Windows Xp   Class 1
Introduction To Windows Xp Class 1puter_geeket
 
1.5 branching and subroutines
1.5   branching and subroutines1.5   branching and subroutines
1.5 branching and subroutinesallenbailey
 
Tutorials3
Tutorials3Tutorials3
Tutorials3raja umair
 
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docx
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docxModule Six Assignment Guidelines and Rubric.htmlOverviewMa.docx
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docxroushhsiu
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2Dan D'Urso
 
Lesson1 windows xp
Lesson1 windows xpLesson1 windows xp
Lesson1 windows xpguevarra_2000
 
ID E's features
ID E's featuresID E's features
ID E's featureswajahat Gul
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | javaRajesh Kumar
 

Similar to 10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx (20)

LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
ArduinoWorkshop2.pdf
ArduinoWorkshop2.pdfArduinoWorkshop2.pdf
ArduinoWorkshop2.pdf
 
Promethean ActivInspire IWB Introduction
Promethean ActivInspire IWB IntroductionPromethean ActivInspire IWB Introduction
Promethean ActivInspire IWB Introduction
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
controlling_animations
controlling_animationscontrolling_animations
controlling_animations
 
controlling_animations
controlling_animationscontrolling_animations
controlling_animations
 
Coding io1--materials for students-group6
Coding io1--materials for students-group6Coding io1--materials for students-group6
Coding io1--materials for students-group6
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
 
Darkroom 2 photoshop masking techniques and smart objects
Darkroom 2 photoshop masking techniques and smart objectsDarkroom 2 photoshop masking techniques and smart objects
Darkroom 2 photoshop masking techniques and smart objects
 
Eclipse Pocket T I P Sn T R I C K S
Eclipse Pocket  T I P Sn T R I C K SEclipse Pocket  T I P Sn T R I C K S
Eclipse Pocket T I P Sn T R I C K S
 
Introduction To Windows Xp Class 1
Introduction To Windows Xp   Class 1Introduction To Windows Xp   Class 1
Introduction To Windows Xp Class 1
 
1.5 branching and subroutines
1.5   branching and subroutines1.5   branching and subroutines
1.5 branching and subroutines
 
Tutorials3
Tutorials3Tutorials3
Tutorials3
 
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docx
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docxModule Six Assignment Guidelines and Rubric.htmlOverviewMa.docx
Module Six Assignment Guidelines and Rubric.htmlOverviewMa.docx
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
Lesson1 windows xp
Lesson1 windows xpLesson1 windows xp
Lesson1 windows xp
 
Lesson1 windo
Lesson1 windoLesson1 windo
Lesson1 windo
 
ID E's features
ID E's featuresID E's features
ID E's features
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
 

More from paynetawnya

YThis paper is due Monday, 30 November. You will need to use at leas.docx
YThis paper is due Monday, 30 November. You will need to use at leas.docxYThis paper is due Monday, 30 November. You will need to use at leas.docx
YThis paper is due Monday, 30 November. You will need to use at leas.docxpaynetawnya
 
You  have spent a lot of time researching a company.  Would you inve.docx
You  have spent a lot of time researching a company.  Would you inve.docxYou  have spent a lot of time researching a company.  Would you inve.docx
You  have spent a lot of time researching a company.  Would you inve.docxpaynetawnya
 
ZXY Corporation has relocated to a new building that was wired and s.docx
ZXY Corporation has relocated to a new building that was wired and s.docxZXY Corporation has relocated to a new building that was wired and s.docx
ZXY Corporation has relocated to a new building that was wired and s.docxpaynetawnya
 
Zero Describe the system (briefly!).  As in I’m going to talk ab.docx
Zero Describe the system (briefly!).  As in I’m going to talk ab.docxZero Describe the system (briefly!).  As in I’m going to talk ab.docx
Zero Describe the system (briefly!).  As in I’m going to talk ab.docxpaynetawnya
 
Youre the JudgeThis week, you are a judge in a federal district c.docx
Youre the JudgeThis week, you are a judge in a federal district c.docxYoure the JudgeThis week, you are a judge in a federal district c.docx
Youre the JudgeThis week, you are a judge in a federal district c.docxpaynetawnya
 
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docx
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docxYour Week 2 collaborative discussion and the Ch. 2 of Introduction.docx
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docxpaynetawnya
 
Your thesis statement will explain the ambiguity of why Prince hal b.docx
Your thesis statement will explain the ambiguity of why Prince hal b.docxYour thesis statement will explain the ambiguity of why Prince hal b.docx
Your thesis statement will explain the ambiguity of why Prince hal b.docxpaynetawnya
 
Your textbook states that body image—how a person believes heshe .docx
Your textbook states that body image—how a person believes heshe .docxYour textbook states that body image—how a person believes heshe .docx
Your textbook states that body image—how a person believes heshe .docxpaynetawnya
 
Your textbook discusses various cultural models in terms of immigrat.docx
Your textbook discusses various cultural models in terms of immigrat.docxYour textbook discusses various cultural models in terms of immigrat.docx
Your textbook discusses various cultural models in terms of immigrat.docxpaynetawnya
 
Your team has been given the land rights to an abandoned parcel of.docx
Your team has been given the land rights to an abandoned parcel of.docxYour team has been given the land rights to an abandoned parcel of.docx
Your team has been given the land rights to an abandoned parcel of.docxpaynetawnya
 
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docx
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docxYour supervisor, Ms. Harris, possesses a bachelors of social work (.docx
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docxpaynetawnya
 
Your RatingGroup DiscussionDelinquency Prevention Please .docx
Your RatingGroup DiscussionDelinquency Prevention Please .docxYour RatingGroup DiscussionDelinquency Prevention Please .docx
Your RatingGroup DiscussionDelinquency Prevention Please .docxpaynetawnya
 
Your report due in Week 6 requires you to look at tools of liquidity.docx
Your report due in Week 6 requires you to look at tools of liquidity.docxYour report due in Week 6 requires you to look at tools of liquidity.docx
Your report due in Week 6 requires you to look at tools of liquidity.docxpaynetawnya
 
Your Project Sponsor pulls you aside and admits that he has no idea .docx
Your Project Sponsor pulls you aside and admits that he has no idea .docxYour Project Sponsor pulls you aside and admits that he has no idea .docx
Your Project Sponsor pulls you aside and admits that he has no idea .docxpaynetawnya
 
Your progress on the project thus far. Have you already compiled i.docx
Your progress on the project thus far. Have you already compiled i.docxYour progress on the project thus far. Have you already compiled i.docx
Your progress on the project thus far. Have you already compiled i.docxpaynetawnya
 
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docx
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docxWeek 6 - Discussion 1Evaluate the characteristics of each mode o.docx
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docxpaynetawnya
 
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docx
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docxWEEK 5 – EXERCISES Enter your answers in the spaces pr.docx
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docxpaynetawnya
 
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docx
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docxWeek 5 Writing Assignment (Part 2) Outline and Preliminary List o.docx
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docxpaynetawnya
 
Week 5 eActivityRead the Recommendation for Cryptographic Key.docx
Week 5 eActivityRead the Recommendation for Cryptographic Key.docxWeek 5 eActivityRead the Recommendation for Cryptographic Key.docx
Week 5 eActivityRead the Recommendation for Cryptographic Key.docxpaynetawnya
 
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docx
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docxWeek 5 DiscussionNetwork SecuritySupporting Activity Netw.docx
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docxpaynetawnya
 

More from paynetawnya (20)

YThis paper is due Monday, 30 November. You will need to use at leas.docx
YThis paper is due Monday, 30 November. You will need to use at leas.docxYThis paper is due Monday, 30 November. You will need to use at leas.docx
YThis paper is due Monday, 30 November. You will need to use at leas.docx
 
You  have spent a lot of time researching a company.  Would you inve.docx
You  have spent a lot of time researching a company.  Would you inve.docxYou  have spent a lot of time researching a company.  Would you inve.docx
You  have spent a lot of time researching a company.  Would you inve.docx
 
ZXY Corporation has relocated to a new building that was wired and s.docx
ZXY Corporation has relocated to a new building that was wired and s.docxZXY Corporation has relocated to a new building that was wired and s.docx
ZXY Corporation has relocated to a new building that was wired and s.docx
 
Zero Describe the system (briefly!).  As in I’m going to talk ab.docx
Zero Describe the system (briefly!).  As in I’m going to talk ab.docxZero Describe the system (briefly!).  As in I’m going to talk ab.docx
Zero Describe the system (briefly!).  As in I’m going to talk ab.docx
 
Youre the JudgeThis week, you are a judge in a federal district c.docx
Youre the JudgeThis week, you are a judge in a federal district c.docxYoure the JudgeThis week, you are a judge in a federal district c.docx
Youre the JudgeThis week, you are a judge in a federal district c.docx
 
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docx
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docxYour Week 2 collaborative discussion and the Ch. 2 of Introduction.docx
Your Week 2 collaborative discussion and the Ch. 2 of Introduction.docx
 
Your thesis statement will explain the ambiguity of why Prince hal b.docx
Your thesis statement will explain the ambiguity of why Prince hal b.docxYour thesis statement will explain the ambiguity of why Prince hal b.docx
Your thesis statement will explain the ambiguity of why Prince hal b.docx
 
Your textbook states that body image—how a person believes heshe .docx
Your textbook states that body image—how a person believes heshe .docxYour textbook states that body image—how a person believes heshe .docx
Your textbook states that body image—how a person believes heshe .docx
 
Your textbook discusses various cultural models in terms of immigrat.docx
Your textbook discusses various cultural models in terms of immigrat.docxYour textbook discusses various cultural models in terms of immigrat.docx
Your textbook discusses various cultural models in terms of immigrat.docx
 
Your team has been given the land rights to an abandoned parcel of.docx
Your team has been given the land rights to an abandoned parcel of.docxYour team has been given the land rights to an abandoned parcel of.docx
Your team has been given the land rights to an abandoned parcel of.docx
 
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docx
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docxYour supervisor, Ms. Harris, possesses a bachelors of social work (.docx
Your supervisor, Ms. Harris, possesses a bachelors of social work (.docx
 
Your RatingGroup DiscussionDelinquency Prevention Please .docx
Your RatingGroup DiscussionDelinquency Prevention Please .docxYour RatingGroup DiscussionDelinquency Prevention Please .docx
Your RatingGroup DiscussionDelinquency Prevention Please .docx
 
Your report due in Week 6 requires you to look at tools of liquidity.docx
Your report due in Week 6 requires you to look at tools of liquidity.docxYour report due in Week 6 requires you to look at tools of liquidity.docx
Your report due in Week 6 requires you to look at tools of liquidity.docx
 
Your Project Sponsor pulls you aside and admits that he has no idea .docx
Your Project Sponsor pulls you aside and admits that he has no idea .docxYour Project Sponsor pulls you aside and admits that he has no idea .docx
Your Project Sponsor pulls you aside and admits that he has no idea .docx
 
Your progress on the project thus far. Have you already compiled i.docx
Your progress on the project thus far. Have you already compiled i.docxYour progress on the project thus far. Have you already compiled i.docx
Your progress on the project thus far. Have you already compiled i.docx
 
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docx
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docxWeek 6 - Discussion 1Evaluate the characteristics of each mode o.docx
Week 6 - Discussion 1Evaluate the characteristics of each mode o.docx
 
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docx
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docxWEEK 5 – EXERCISES Enter your answers in the spaces pr.docx
WEEK 5 – EXERCISES Enter your answers in the spaces pr.docx
 
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docx
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docxWeek 5 Writing Assignment (Part 2) Outline and Preliminary List o.docx
Week 5 Writing Assignment (Part 2) Outline and Preliminary List o.docx
 
Week 5 eActivityRead the Recommendation for Cryptographic Key.docx
Week 5 eActivityRead the Recommendation for Cryptographic Key.docxWeek 5 eActivityRead the Recommendation for Cryptographic Key.docx
Week 5 eActivityRead the Recommendation for Cryptographic Key.docx
 
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docx
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docxWeek 5 DiscussionNetwork SecuritySupporting Activity Netw.docx
Week 5 DiscussionNetwork SecuritySupporting Activity Netw.docx
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx

  • 1. 10. USING THE ECLIPSE DEBUGGER updated: 8/6/18 This tutorial assumes that you have previously completed the Getting Started with Eclipse tutorial. Since much of what you're going to do for this tutorial is identical to what you've done for that tutorial, I will refrain from providing all the details this time. If you don't remember the details of how to do something, look it up in the previous tutorial. This tutorial uses x: to refer to the drive that you're saving your work to. In the lab, x: should be replaced by the USB drive (assuming that you're using a USB flash drive storage device). At home, x: should be replaced by the USB drive or the hard drive, whichever you prefer. Whenever you are asked to perform an action (left column below) that you've already done before, I will refrain from providing the supplemental information (right column below). If you don't remember the details of how to do something, look for it earlier in the tutorial. I expect you to have to look up a lot of previously covered material. This is my attempt to force you to memorize how to do things. Actions Supplemental Information Load Eclipse.
  • 2. Create a project named tutorial2. In creating a tutorial2 project, Eclipse will 1) create a tutorial2 folder and put it in your workspace folder, and 2) create a .project file and put it in your tutorial2 folder. Within your tutorial2 project, create a source code file named MouseDriver.java and enter this text: public class MouseDriver { public static void main(String[] args) { String temp = "stan"; Mouse mickey = new Mouse(temp + "dard", 100, 10); Mouse fivel = new Mouse("standard", 100, 10); mickey.printStatus(); mickey.simulateGrowth(4); mickey.printStatus(); fivel.simulateGrowth(4); if (mickey.equals(fivel)) { System.out.println("They're equal"); } } // end main } // end class MouseDriver Save the source file. Within your tutorial2 project, create a source code file named Mouse.java and enter this text: public class Mouse { private String variety; // standard, hairless, etc.
  • 3. private int weight; // the mouse's weight in grams private int growthRate; // % that mouse grows each day private int days; // # of simulated days so far public Mouse(String v, int w, int gR) { variety = v; weight = w; growthRate = gR; } // end Mouse constructor public void simulateGrowth(int d) { days += d; while ((d > 0) || (weight > 0)) { weight += growthRate/100 * weight; d--; } } // end simulateGrowth public void printStatus() { System.out.println("After " + days + " days, " + " weight = " + weight + "."); } // end printStatus public boolean equals(Mouse otherMouse) { boolean varietyCheck, weightCheck; varietyCheck = (variety == otherMouse.variety); weightCheck = (weight == otherMouse.weight); return varietyCheck && weightCheck; } // end equals } // end class Mouse Save the source file.
  • 4. Build (i.e., compile) the tutorial2 project. If necessary, fix compilation errors. Run the project. This should appear in the output pane: After 0 days, weight = 100. Study the main method to figure out if the output is correct. Note that the main method contains two calls to the printStatus method. You may safely assume that the first call to printStatus was responsible for printing the above status message. But why doesn't main's second call to printStatus generate a second status message? The second status message is missing because, in executing the program, the Java Virtual Machine (JVM) never reaches the second call to printStatus. Terminate the program. Note the red button at the top of your output window. The red button’s redness indicates that the program is still running. So why is the program still running? Hmmm ... We'll figure that out eventually. For now, terminate the program by clicking the red button. (Makes sense, right? Red for stop.) As the program terminates, the red button should become non- red. Switch to the debug perspective. Click the Window menu. Select Perspective / Open Perspective.
  • 5. Select Debug from the pop-up sub-menu. That should cause the window's appearance to change to the debug "perspective." You should see Debug and Java buttons in the top-right corner of your window. For practice purposes, click the Java button. That should cause your window to revert back to its normal mode, the Java perspective. Click the Debug button to return to the debug perspective. Display the MouseDriver.java file. In your debug perspective, you should see tabs for your project's source code files in the middle left pane. More specifically, you should see Mouse.java and MouseDriver.java tabs. Click the MouseDriver.java tab. Your window should look approximately like this: Understand the debug perspective. Note the five panes in the debug perspective. The top left pane is called the Debug pane. The Debug pane shows the status of the currently running program or the status of the just- completed program. An exit value of 0 means the program ended normally. An exit value of 1 means the program ended abnormally. The top right pane shows two tabbed panes. The Variables pane shows the current state of program variables while the program is running. The Breakpoints pane shows the status of breakpoints within the program. A breakpoint is a marker. When the debugger reaches a breakpoint marker, it stops executing the program and waits for the user's next instruction.
  • 6. The middle right pane is the Outline pane. It shows the instance variables and methods for the source code file that's currently chosen in the middle left pane. The bottom pane shows two tabbed panes – Console and Tasks. The Console pane shows the console-based output generated by the program and the input entered by the user. Set a breakpoint. In debug mode, you'll need to specify one or more lines in your program as breakpoints so that when you run your program, the debugger will stop at the breakpoints. If you don't set a breakpoint, then when you run your program, the debugger will run the same as it ran in non-debug mode. Click your mouse on the first executable line in your MouseDriver.java source code (click on the String temp = "stan"; line). Click the Run menu. Note the Toggle Breakpoint option. At the right of the Toggle Breakpoint option, you should see Ctrl+Shift+B. That's a hotkey shortcut. Ctrl+Shift+B means that to set a breakpoint, you can hold down the Ctrl and Shift keys and then tap the b key (b for break). This time, don't use the hotkey shortcut; instead click on the Run menu's Toggle Breakpoint option. After setting the breakpoint, you should see a bullet in the gray area at the left of the breakpoint line. For practice purposes, press Ctrl+Shift+B and notice how the bullet disappears. Press Ctrl+Shift+B again and notice how the bullet reappears. Initiate a debug session Click the Run menu. Select Debug As. Select Java Application from the pop-up sub-menu.
  • 7. That should cause the debugger to run to the first breakpoint line. The first executable line (String temp = "stan";) should be highlighted. Examine the Step Over option. Click the Run menu. Note the Step Over option. If your Step Over option (and other debug options) are grayed out, that means they are deactivated and unusable. If that’s the case, then you might have external software that’s hindering your debug session. On my home computer, my McAfee software prompted me with “Do you want to allow javaw.exe to access the Internet?” When I clicked “Allow,” my Eclipse debug options became active. Understand different techniques for stepping over a line of code. At left of the Run menu’s Step Over option, you should see an icon with an underscore and an arrow jumping over it. At the right of the Step Over option, you should see the hotkey shortcut, F6. Those labels indicate alternative shortcut ways to select the Step Over option. To use that shortcut, you can click on the same-looking button above the Debug pane. To use F6, you can simply press the F6 key. Of course, as a third alternative, you can click on the Run menu's Step Over option. Back out of the Run menu by pressing the Esc key. Step over two lines of code. Now initiate two step-over actions by 1) clicking the icon with the arrow jumping over the underscore and then 2) pressing F6. Step into the code. Notice that the step-over action causes the debugger to jump to the line that's positioned immediately below the current line in the program. Sometimes you won't want to jump there. Instead you'll want to jump inside of the method or constructor that the
  • 8. current line is calling. The debugger should now be highlighting the line that instantiates the second Mouse object. With the first instantiation line, you performed a step-over command. This time, we want you to perform a step-into command so that you can see what happens when the Mouse object is created. Click the Run menu. Click Step Into (as always, feel free to use the alternative shortcut methods as specified by the labels on the Step Into option). The step-into action causes the debugger to jump into the module (constructor or method) that the current line is on. In this case, the module is a constructor. Notice how the constructor assigns the three passed in argument values to the three instance variables. Step until printStatus is highlighted. Perform the step-over action several times and that should take you through and then out of the Mouse constructor. Perform the step-over action until the printStatus line is highlighted. Step into the printStatus method. Perform the step-into action to jump into the printStatus method. Perform the step-into action again while the System.out.println line is highlighted. Practice stepping into and out of an api method. Normally, you won’t want to step into an API method (System.out.println is an API method) because there's no need to debug API methods. However, sometimes you'll step into a
  • 9. method accidentally. To step out of a method, click the Run menu and then select the Step Return option. Perform the step- return action so that the System.out.println line is once again highlighted. Perform the stepover action several times until the mickey.simulateGrowth(4) line is highlighted. Step into the simulateGrowth method. View the values for the simulateGrowth method's variables. While inside the simulateGrowth method, view the Variables pane (click the Variables pane's tab if necessary). In the Variables pane, you should see the d parameter and the this reference. The d parameter should display the value 4. Click the this reference's expansion icon (a triangle) to display the calling object's instance variables. The weight variable should display a value of 100 and the growthRate variable should display a value of 10. Step through the simulateGrowth method. Perform a number of step-over actions and observe how the d variable decrements correctly and observe how the weight variable does not behave correctly (it does not change its value at all). Why does weight's value not change? Inspect expression values. Highlight the growthRate/100 * weight expression and then right click. Select Inspect from the pop-up menu. Note that the Inspect feature allows you to evaluate an entire expression (whereas the Variables pane only displays values for individual variables).
  • 10. Note that the expression's value is 0. Why? Close the Inspect window by clicking anywhere outside of the inspection box. Highlight the growthRate/100expression and inspect its value. Note that the expression's value is 0. Why? Integer division! Find the declaration for the growthRate instance variable. Note that it's declared as an int. 10 / 100 does indeed evaluate to 0. What's the solution? Fix the bug. Terminate the program by clicking the red button in the Debug pane or the red button in the Console pane. Edit the growthRate declaration so that it's declared as a double instead of an int. Run the project in normal mode. Although you're using the debug perspective, it's possible to run your program in normal mode, with debugging turned off. To run a program, you need to select the source code pane for the class that contains main, so click the MouseDriver.java tab. Click the Run menu. Select Run As. Select Java Application from the pop-up sub-menu. The program, unfortunately, produces the same results as before – one line of output from the printStatus method and no program termination. Don’t get mad and assume that your fix
  • 11. from before didn't help. Instead, realize that you have additional bugs to fix. Please remember that patience is a virtue in the programming profession! Terminate the program. Set a breakpoint in the simulateGrowth method. This time, instead of stepping all the way through the program until we get to simulateGrowth's loop, let's take a shortcut by setting a breakpoint within the loop and then running the program up to that breakpoint. Before adding the new breakpoint, let's remove the old breakpoint. Select the Breakpoints pane. Look for the Remove All Breakpoints button (the button with the two X's on it) and click it. In the Mouse pane, scroll to the while loop in the simulateGrowth method. Add a breakpoint to the weight += … line. Initiate a debug session. If you want to use the Run menu to initiate your debug session, you first have to select the MouseDriver.java pane. As a shortcut alternative to using the Run menu, feel free to use the debug button at the top of the window. It's the button with the bug picture on it. In clicking the button, it runs the program that was previously run. Since you previously ran the MouseDriver program, the debug button should work fine. Hover your mouse over the debug button. That should cause the microhelp text "Debug MouseDriver" to pop up.
  • 12. Click the button in order to run your MouseDriver program in debug mode. The debugger should execute your program up to the breakpoint line. The debugger's current line (as indicated by an arrow at the left of the line) should now be on the weight += … line. Run to the next breakpoint. Click the Run menu. Select Resume. The debugger should run through the loop one time and stop at the weight += line once again. Select the Variables pane and note that the d and weight values are updated appropriately. Run to the next breakpoint four more times in succession. Note that the d value decrements past zero and becomes a negative number. The loop was supposed to terminate when d reached zero. What's the bug? Fix the bug. Terminate the program. Change the while loop's condition so that it uses && instead of ||. Run project in normal mode. This time, the program should terminate successfully and both printStatus method calls should generate reasonable output. Since the main method initializes both Mouse objects with the same values, we'd expect the "They're equal" message to be printed. Why is it not printed? Apparently the equals method returned a false instead of a true. But why?
  • 13. Initiate a debug session. The debugger should execute the program up to the simulateGrowth breakpoint line. Remove the breakpoint in simulateGrowth. Find the breakpoint line in simulateGrowth. Click on the breakpoint line and then press Ctrl+Shift+B. The reason that we had you remove the breakpoint in simulateGrowth is because we're no longer interested in tracing through the simulateGrowth method. Instead, we're interested in tracing through the equals method. Set a breakpoint in the equals method. Note that breakpoints can only be set on executable lines of code. Method headings are not considered to be executable lines of code. This line is the first executable line of code in the equals method: varietyCheck = (variety == otherMouse.variety); Set a breakpoint on that line. Initiate a debug session. The debugger should execute the program up to the equals breakpoint line. View the values for the equals method's variables. While inside the equals method, view the Variables pane (click the Variables pane's tab if necessary). In the Variables pane, you should see the this reference and the otherMouse reference.
  • 14. Since they're both reference variables, they should have expansion icons at their left. Click the expansion icons to reveal the values of their instance variables. Inside a method, a calling object's instance variables are often written without a "reference variable dot" prefix. Thus, the variables that appear to the left of the "==" operators (variety, weight, and growthRate) are the calling object's instance variables. The Variables pane shows that the calling object's variety, weight, and growthRate instance variable values are the same as the otherMouse's variety, weight, and growthRate instance variable values. So why didn't the equals method return a true when we previously ran the program? For this bug, the Variables pane is actually not all that helpful. It looks like the instance variable values are all the same, but are they really ... ? Step over the varietyCheck assignment statement. Inspect the varietyCheck variable. In the Inspect window, varietyCheck's value is false. Why? Remember that variety is a String and a String is a reference variable and a reference variable holds an address. The address stored in mickey's variety instance variable is different from the address stored in fivel's variety instance variable. Thus, the == operator yields a value of false. What's the solution? Fix the bug. Terminate the program.
  • 15. Change the variety's test for equality so that it uses .equals instead of ==. Run the project in normal mode. This time, the program should generate reasonable output for the two printStatus method calls and it should print "They're equal". Exit from Eclipse. 11. GETTING STARTED WITH ECLIPSE updated: 8/6/18 OBTAINING AND INSTALLING ECLIPSE FOR YOUR HOME COMPUTER: Since Eclipse is installed in the lab, obtaining it for your home computer is recommended, but not required. I couldn't find an official listing of Eclipse's system requirements. The following specifications are cobbled together from various sites that use Eclipse: · 512 MB RAM minimum (1 GB RAM recommended) · 1 GB hard disk space minimum If your home computer meets the system requirements and you'd like Eclipse for home usage, then read the rest of this section.
  • 16. Otherwise, jump to the next section. Eclipse is an Integrated Development Environment (IDE) that allows you to enter, compile, and run programs. The programs can be written in one of many different languages. In order to make a particular language work in Eclipse, the language's compiler must be installed. The compiler installation is separate from Eclipse's installation. To obtain the Java compiler, go to this website: http://www.oracle.com/technetwork/java/javase/downloads On that website, you'll see various options for downloading the Java Standard Edition (SE) software. Feel free to read about all the download options and download the ones you want, but the only one you'll really need is the most recent Java SE 10 JDK download option (JDK stands for Java Development Kit). Click the associated JDK Download link. Using the website's prompts as a guide, you might have to follow a series of instructions and links in order to find the JDK download link that matches your particular operating system. Click on that link and save the file by downloading it to your computer. After the download completes, install the JDK as directed. During the installation process, you will be given the opportunity to select different setup options. I accept the default, which is to install everything, but if you want to save space, you should be able to deselect the Source Code, Public JRE, and Java DB setup options. To obtain Eclipse, go to this website: http://www.eclipse.org/downloads Click on the Download button under the Get Eclipse heading and follow the instructions.
  • 17. After the download completes, install Eclipse as directed. From the menu of installation options, click on the Eclipse IDE for Java Developers option (not the Eclipse IDE for Java EE Developers option). That should generate an installation window. Feel free to accept the default installation folder. For me, the default installation folder was C:UsersJohnjava- oxygen, which I don’t like, so I used File Explorer to create a new folder named “eclipse Photon” and then I entered “c:eclipse Photon” in the installation folder field (I tried to use my hard drive’s root folder and my Program Files folder, but neither of those folders worked due to permissions problems). You can accept your default installation folder or try getting a different folder to work. You should see checkboxes for Create start menu entry and Create desktop shortcut, and those boxes should be selected. Click the Install button. After the installation completes, close the installation window. SAVING FILES: · Naturally, you are required to save your program files. In the lab, you are required to save your files on a USB flash drive storage device. If you're working at home, you may save your save your files on your computer's hard disk, but you're still required to have a flash drive so that you can transport your files to and from school. If you're at the school's lab, do not use the hard disks ever! TUTORIAL: When working on homework assignments, use Eclipse to enter, debug, and run your programs. If you forget how to do something in Eclipse, it is up to you to carefully reread this Eclipse tutorial and figure out how to do things. To reduce the number of rereads, go through this tutorial slowly and try to remember what you're doing.
  • 18. This tutorial uses x: to refer to the drive that you're saving your work on. In the lab, x: should be replaced by the USB drive (assuming that you're using a USB flash drive storage device). At home, x: should be replaced by the USB drive or the hard drive, whichever you prefer. Whenever you are asked to perform an action (left column below) that you've done before, I will refrain from providing the supplemental information (right column below). If you don't remember the details of how to do something, look for it earlier in the tutorial. I expect you to have to look up a lot of previously covered material. This is my attempt to force you to start memorizing how to do things. Actions Supplemental Information Start Eclipse. Click on the Start menu. Click on Eclipse. Create a workspace. Clicking Eclipse (above) should cause a Workspace Launcher dialog to appear. In the Workspace box, enter x:219pgms. Since this is the first time you've specified x:219pgms in the workspace box, you'll be creating a new workspace – the 219pgms workspace. The 219pgms workspace is contained in the 219pgms folder. If the 219pgms folder doesn't exist, Eclipse will create it for you automatically. Make sure the "Use this as a default and do not ask again" box is unchecked. Click OK.
  • 19. Clicking OK should cause Eclipse to create the 219pgms workspace and load a Welcome screen. Go to the workbench. It's not required, but feel free to explore the Welcome screen's links. The workbench is the area where you'll do all your work – where you'll enter, debug, and run code. To close the Welcome screen and go to the workbench, click on the screen’s Workbench button in the top-right corner. If there was no prompt for workspace. If you ever load Eclipse and the Workspace Launcher dialog doesn't appear, that means someone checked the "Use this as a default and do not ask again" box. That's a bad thing (particularly in the lab) because then all users are taken to the same workspace location and that location might be inappropriate. To correct this problem, perform these steps after getting to the Eclipse workbench: Click the Window menu. Select Preferences. That should cause a Preferences window to appear. In the container tree at the left of the Preferences window, expand the General container by pressing the symbol at its left. Expand the Startup and Shutdown container, and inside the container, select the Workspaces option. Make sure the "Prompt for workspace on startup" box is checked. Click Apply and Close. Make sure you’re using the Java perspective. Eclipse can be used for many different languages. If the previous Eclipse user used it for a language other than Java, switch the Eclipse perspective back to Java.
  • 20. In the top-right corner of your workspace window, you should see icons for the perspectives that Eclipse has used in the past. You should see a Java perspective icon (look for a J), and it should be selected. If it’s not selected, select it. If you want to select it, but can’t see it as a selection option, select Window / Open Perspective / Other… In the Open Perspective dialog, select Java and then click Open. Make sure your Java JDK and JRE settings are correct. Click the Window menu. Select Preferences. That should cause a Preferences window to appear. In the container tree at the left of the Preferences window, expand the Java container by pressing the symbol at its left. Select the Compiler option, which should generate a Compiler frame. In the Compiler compliance level field, make sure the Java version that you just installed is selected. In the Java container at the left, select the Installed JREs option. In the Installed JREs frame, make sure the Java version that you just installed is selected. If it’s not displayed as an option to select, use the Add button to search for it and add it. Click Apply and Close. How to set coding-style preferences. You'll now set Eclipse's coding-style preferences so they match the ICS Program’s coding-style conventions. Select Window / Preferences. That should cause a Preferences window to appear. In the container tree at the left of the Preferences window, expand the Java container and then the Code Style sub- container. Select the Formatter option.
  • 21. In the Active profile box, make sure that Java Conventions is selected. Click the Edit… button. That should cause a Profile window to appear. In the Profile window, click the Indentation tab. In the Tab policy drop-down box, select Spaces only. In the Indentation size box, enter 2. In the Tab size box, enter 2. Make sure that the Align fields in columns box is unchecked. Make sure all the boxes in the Indent section are checked, except for the Empty lines box. Click the Braces tab at the top of the Profile window. For all the boxes except the array initializer box, make sure that Next line is selected. For the array initializer box, make sure that Same line is selected. Click the White Space tab at the top of the Profile window. Expand the Arrays container. Select the Array initializers option. Make sure that the after opening brace and before closing brace boxes are unchecked. The rest of the default code-style formatter profile closely matches the ICS Program’s coding-style conventions, so there's no need for any more adjustments to it. In the Profile name box at the top of the Profile window, type ICS Program. Click OK. How to set default build path for new Java projects. To keep things simple, you should store your source-code files and your bytecode files in the same folder as the project’s root folder. This step specifies that policy as your default.
  • 22. In the Preferences window’s expanded Java container, select the Build Path container. In the Build Path frame, select the Project option. Click Apply and Close to close the Preferences window. How to export preferences. I recommend that you put all of your homework into the same workspace. That way you can share your workspace's coding- style preferences. Nonetheless, there will probably come a time when you'll want to create a new workspace. When you do so, I recommend that you export your original workspace's coding- style preferences to an external file and then import that file into your new workspace. Here's how to export: Select File / Export…. That should cause an Export window to appear. In the container tree at the left of the Export window, expand the General container. Select the Preferences option. Click Next. That should cause an Export Preferences window to appear. Make sure the Export all box is checked. In the To preference file box, select the folder and file where you want to store your preferences file (I selected x:eclipse oxygen) and followed by the filename ICS_Profile. Click Finish. Note that a .epf extension is appended to the filename by default. If you'd like to test that your export worked, shut down Eclipse, open up a new workspace, and attempt to import the ICS_Profile.epf file. What is a project?
  • 23. A project is an entity that helps to organize all the files in a particular program. A project's settings are stored in a .project file. The .project file is contained in the project's folder. How to organize your projects. I recommend that you use one workspace to store all your CS 219 projects. In this tutorial, you've already created a 219pgms workspace and you will create a tutorial project within that workspace. The 219pgms workspace uses a 219pgms folder. The tutorial project will use a tutorial folder which is a subfolder of 219pgms. For your homework assignments, I recommend that you create hw1, hw2, etc. projects within the 219pgms workspace. Create a project. Select File / New. In the pop-up submenu, select Project…. That should cause a New Project window to appear. In the New Project window’s container tree, expand the Java container and then select the Java Project option. Click on the Next button. That should cause a New Java Project window to appear. If someone has previously created an Eclipse Java project (which would be the case if you are in the lab), then, as a shortcut alternative to selecting Project… / New Project, you can select Project… / New Java Project , and that should cause a New Java Project window to appear immediately. In the Project name box, enter tutorial. Verify that in the Project layout area, “Use project folder as root for sources and class files” is selected. Click the Next button. Click the Finish button.
  • 24. Verify project creation. Go to File Explorer and locate the x:219pgmstutorial folder. Verify the existence of the .project file within the tutorial folder. If you don't see the tutorial folder, try double clicking on the 219pgms folder. Find Package Explorer. At the left of your Eclipse window, you should see a Package Explorer pane that contains your workspace's project folders. If the package explorer pane is not shown, open it as follows: Select Window / Show View. Select the Package Explorer option. Create a source code file. In the Package Explorer frame, right click on the tutorial project. Select New from the pop-up menu. Select File from the pop-up submenu. That should cause a New File window to appear. In the New File window, select the tutorial folder. In the File name box, enter Hello.java. Click the Finish button. That should cause an empty Hello.java frame to appear in the workbench. Enter this text: Enter this text in the Hello.java frame such that <your name> is replaced with your actual name. /**************************************** * Hello.java * <your name> * * This program says "hello" to the world. ****************************************/
  • 25. public class Hello { public static void main(String[] args) { System.out.println("Hello world!"); } // end main } // end class Hello Understand the code. The top section is known as the prologue section. It provides documentation for human readers. The compiler ignores everything between the opening /* and the closing */. main methods should be enclosed in a class that is public and whose name matches the name of the enclosing file. For example, the main method above is enclosed in a public class named Hello. The class must be named Hello since the enclosing file is named Hello.java. Save the source file. Click on the save icon (the save icon looks like a diskette). Compile your program. Click the Project menu. If the Build Automatically option is checked, click it (so that it becomes unchecked). Click the Project menu. Select the Build All option or the Build Project option. If necessary, fix compilation errors. Click the Problems tab at the bottom of the workbench window. There should be no errors in the Problems frame, but if you entered something incorrectly and there are errors, fix them. Run the program. Make sure that the cursor is somewhere within your program’s
  • 26. source code. Click the Run menu. Select the Run option. That should cause a progress-bar dialog box to appear (with a fast computer, you won’t be able to see it). The progress bar indicates that a main method is being searched for. The default place to find the main method is in the workbench's current class (i.e., the class that's currently displayed). For the current case, the main method is found in the Hello class. After the progress-bar dialog box disappears, the Console tab should appear in the bottom of the workbench window. Click on the Console tab. That should cause Hello world! to appear in the Console frame. If necessary, fix runtime errors. Create a second program. To create a new program, you can of course enter it from scratch as you did for the Hello.java program. As a shortcut, this time we'll copy from an existing program and edit the copy. Find your program in the Package Explorer pane. In the Package Explorer pane, look for the tutorial container and expand it by pressing the symbol at its left. In the tutorial container, look for the (default package) container and expand it. Look for your Hello.java file inside the default package container. Copy your program. Right click on your Hello.java file. In the pop-up menu, select Copy. Right click on the tutorial project.
  • 27. In the pop-up menu, select Paste. That should cause a Name Conflict dialog to appear. In the new name box, enter Countdown (no need to enter the .java extension). Click OK. That should cause a Countdown.java file to appear in the tutorial project. Open the Countdown.java file. Double click on the Countdown.java file. Edit the Countdown.java file. Edit the Countdown.java file so that it contains this: /**************************************************** * Countdown.java * <your name> * * This program prints a countdown from a user-entered * starting position. ****************************************************/ import java.util.Scanner; public class Countdown { public static void main(String[] args) { int startPos; // starting position for countdown Scanner stdIn = new Scanner(System.in); System.out.print("Enter countdown starting position: "); startPos = stdIn.nextInt(); for (int i=startPos; i>0;) {
  • 28. System.out.println(i + "..."); } System.out.println("Lift off!"); } // end main } // end class Countdown Ignore resource leak. If you see a warning for the stdIn initialization statement, you can ignore it. If you want an explanation, see http://www.coderanch.com/t/590921/java/java/Scanner- Resource-leak. Save the Countdown.java source file. Compile your program. Note that the build commands compile more than just the one file that's displayed in the source-code frame. The Build All command compiles all the files in your workspace and the Build Project command compiles all the files within your project. At this point, there's only one project in your workspace, so both build commands compile the same files - Hello.java and Countdown.java. If necessary, fix compilation errors. Run the program using the run icon. As a shortcut alternative to using the Run menu, this time, run your program using the run icon. More specifically, look at the top of the workbench for a green-circle icon with a white triangular arrow inside it. Hover your mouse over the icon. That should cause the message Run Countdown to pop up. Click the icon in order to run your Countdown program.
  • 29. Open the Console frame. You should see a prompt to enter the countdown starting position. To move your cursor to the prompt area, click within the Console frame. Enter 30. After pressing enter, your Console frame should be filled with multiple lines of 30... Why is your Console frame filled with multiple lines of 30... ? Terminate the program. Your program is repeatedly printing the line 30... That's an example of an infinite loop. Note the red button at the upper-right corner of your Console frame. The red button allows the user to terminate a program that's currently running. (Makes sense, right? Red for stop.) To stop the infinite loop, click the red button. As the program terminates, the red button should become non- red. Find the error. An infinite loop is an example of a run-time error. Run-time errors are often more difficult to debug than compilation errors because you do not have the benefit of a compiler-generated error message. Can you figure out the error? Do not continue until you attempt to find the error. Fix the error and recompile. That's right, the for loop heading is missing its third component. Replace the for loop heading with this line: for (int i=startPos; i>0; i--) Save Countdown.java and recompile.
  • 30. Run the program. After initiating the run process, you should be prompted to enter the countdown starting position. Enter 30. Your Console frame should display this: Enter countdown starting position: 30 30 ... 29 ... <28 through 2 go here> 1 ... Lift off! Note that you'll probably need to scroll up and down to see the entire output. If necessary, fix errors. Copy the program's output into a Word document. Next, you'll learn how to copy your program's output into a Word document. You'll need to do this for every homework project. Use your mouse to select the output (in the Console frame). Press Ctrl+c to copy the selected text. Your output is now copied to your computer's buffer. You'll next need to paste it into a Word document. Open a new Word document. To paste the previously copied text into the Word document, make sure your cursor is within the Word document and then press Ctrl+v. Save the Word document in a file named tutorial.docx. Copy the program's source code into a Word document. Make sure your cursor is in the Eclipse source code window.
  • 31. Press Ctrl+a to highlight your entire program. Press Ctrl+c to copy the highlighted text. Go to your tutorial.docx Word document. Insert your cursor just prior to your output. Press Ctrl+v to paste your source code just prior to your output. Press the Enter key several times in order to separate your source code from your output. Apply monospace font to your source code. For every homework project, you're required to use monospace font for your project source code and project output. Font refers to the appearance of characters. Monospace fonts are fonts such that each character is the same width. Using monospace font ensures that text that's supposed to be aligned stays aligned when it's printed. In your homework projects, if your source code or output is not aligned properly, you will lose style points. To apply monospace font to your Word document's source code, drag your mouse across the source code so that it becomes highlighted. Use Word’s font name scroll bar to search for Courier New (a popular monospace font), select it, and click OK to apply your font selection. Apply monospace font to your output. Save your Word document and Exit from Word. Exit from Eclipse. Click the X in the top-right corner or select Exit from the File menu. Start Eclipse This time when you start Eclipse, the Workspace Launcher dialog should display x:219pgms as the suggested workspace.
  • 32. Click OK. That should cause Eclipse to load your 219pgms workspace and your tutorial project. If the workspace launcher doesn't work. I've found that I'm occasionally unable to reload a workspace. If that happens, use File Explorer to delete the workspace's .metadata folder. Then (re)create your workspace as described above. Exit from Eclipse. CS 219 - HOMEWORK 1 due: Thu, 8/23/18 HOMEWORK SUBMISSION POLICIES: · Put all of your work, even project source code and project output, into a single homework document, and submit that document to the course website by midnight of the day that the homework is due. Put your name at the top of that document. · Make sure that the problems in your homework document are in the same order as the problems in the homework assignment. · In your homework document, make sure that you use monospace font for your project source code and project output. The monospace font ensures that text that's supposed to be aligned stays aligned when it's printed. If your printed source code is not aligned properly, you will lose style points. To achieve monospace font, highlight the relevant text, right click, and select Font. In the Font window, search for Courier New, select it, and click OK to apply your font selection.
  • 33. MANDATORY UNGRADED WORK: Read my Getting Started with Eclipse tutorial. As you read the tutorial, perform the steps as described in the tutorial. If you haven't done so already, print my Homework Assignment Guidelines – Java Programming document and my Java Coding Conventions Guidelines document. You must follow the guidelines found in those documents. Read the documents now! PRACTICE PROJECT (Do not submit an answer because the answer will be provided): Provide a complete program that handles the processing of Rectangle objects. Your Rectangle class should contain: · two instance variables, height and width, that keep track of a rectangle's dimensions · a static variable, numOfRectangles, that keeps track of the total number of instantiated rectangles · A 0-parameter constructor · A constructor that receives two parameters, height and width · getNumOfRectangles – a method that retrieves the number of instantiated rectangles · addHeight – a method that receive an int parameter and adds the parameter's value to the height variable (Note: The addHeight method must be implemented so as to enable method call chaining.) · addWidth – a method that receive an int parameter and adds the parameter's value to the width variable (Note: The addWidth method must be implemented so as to enable method-call chaining.) · printArea – a method that print's the rectangle's area Write your code such that the following main method would produce the output shown below. public static void main(String[] args)
  • 34. { Rectangle r1 = new Rectangle(); r1.printArea(); Rectangle r2 = new Rectangle(2, 4); r2.printArea(); r2.addHeight(3).addWidth(3); r2.printArea(); System.out.println( "Total number of rectangles = " + Rectangle.getNumOfRectangles()); } // end main Output: Rectangle's area = 0 Rectangle's area = 8 Rectangle's area = 35 Total number of rectangles = 2 As always, your program should mimic the output format precisely. Submit answers for all of the following questions. EXERCISES: The following exercise questions refer to material in the Getting Started with Eclipse tutorial. 1. In Eclipse, what is the name of the file that stores a project's settings? (The project-settings file is different from the file that stores coding-style preferences.) 2. What button should you click to terminate the currently running program?
  • 35. 3. When you print your output, why is it important to use monospace font for your program output and program source code? PROJECT: Provide a complete program that stores scores for individual exams and calculates the average score and grade for all exams combined. Specifically, provide an ExamScore class that contains these attributes: · Named constants for the letter grade minimum cutoff values. Use A = 0.9, B = 0.8, C = 0.7, and D = 0.6. Generate an F for a score less than .6 · The number of exams. · The maximum number of points possible on each exam (every exam has the same number of maximum points, so use a variable that’s shared between all the objects). · The total points earned on all exams combined. · The points earned on a particular exam. For each of your variables, think about whether it should be a named constant, a class variable, an instance variable, or a local variable. As always, use the most appropriate kind of variable for the variable’s intended purpose. You are welcome to provide additional constructors and methods, but at a minimum, your ExamScore class should implement these constructors and methods: · 1-parameter constructor –Assign a passed-in earned points value to the exam object’s earnedPoints attribute. Update the total number of exams and the total earned points for all exams combined. · setMaxPointsForEachExam – A standard mutator method for the maxPointsForEachExam variable.
  • 36. · printScore – Print the calling object exam’s score and letter grade. For additional details, see the output, below. · printCombinedScore – Print the score and letter grade for all grades combined. For additional details, see the output, below. Use appropriate modifiers for methods. The modifiers we’ve discussed so far are private, public, and static. You are required to use a helper method if it is appropriate to do so. Provide a main driver method. It should: · Call setMaxPointsForEachExam such that 100 is assigned as the maximum score for each exam. · Instantiate four ExamScore objects and store them in the variables exam1, exam2, exam3, and exam4. In the instantiations, initialize the objects to these values: exam1: 70.5 earned points exam2: 90 earned points exam3: 79.5 earned points exam4: 78 earned points · For exam1, exam2, and exam3 (but not exam4), call printScore. · Call printCombinedScore. Output, using the main driver method described above: On this exam, you earned 70.5 out of 100.0 possible points: C On this exam, you earned 90.0 out of 100.0 possible points: A On this exam, you earned 79.5 out of 100.0 possible points: C On all exams combined, you earned 318.0 out of 400.0 possible points: C As always, your program should mimic the output format precisely. EXTRA CREDIT (2 pts):
  • 37. Add functionality to your ExamScore class such that it can calculate the average score and grade with the lowest exam score thrown out. If you call your new printCombinedScoreWithLowestRemoved method after instantiating four exams as described above, your program should display this: With your lowest exam thrown out, you earned 247.5 out of 300.0 possible points: B Your printCombinedScoreWithLowestRemoved method should not permanently remove the lowest score. So the output from printCombinedScore should be the same regardless of whether you call it before or after you call printCombinedScoreWithLowestRemoved.