Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
If you are completing this lab on a lab computer, and this is the first time (this semester) that you are using Eclipse on a lab computer, follow the instructions for "Installing and Configuring the IDE" on the course "Help" page starting after the step "Install Eclipse" (which has already been done on the lab computers).
If you are using your own computer and you have not yet done so, follow the instructions for "Installing and Configuring the IDE" on the course "Help" page.
eclipseskills
. To do so,
first click on
File+New+Java Project.
(Note: If Java Project is not an option, you may need to
select Other... and expand Java.)
Then, enter
eclipseskills
in the "Project name" field, select
"Use default location", unselect "Create module-info.java file",
and click on Finish.
PictureFrame.java
into the src
directory/folder in the eclipseskills
project.
When prompted, select "Copy files" and click on OK.
(Note: If Eclipse does not allow you to do this, it may be because your
are not using the "Java Perspective".)
src
folder/directory and the
(default package)
so that you can see
that PictureFrame.java
has been copied.
PictureFrame.java
to open it.
The second way to add a source file to a project is to create it in Eclipse. Specifically:
WhatAnEgo
in the default package of the project named eclipseskills
.
That is,
click on File+New+Class,
enter WhatAnEgo
in the "Name" field, make sure the
"Package" field is blank, select "public static void main(String[] args)",
deselect all other "stubs", deselect "Generate comments", and
click on Finish. (Note: Eclipse may warn you that
you should not use the default package. You should ignore that
warning.)
WhatAnEgo.java
?
WhatAnEgo.java
?
TODO
? (Note: This will happen any time a comment
that contains the text TODO
and is a good way to include
reminders in your source code.)
main()
method (i.e., the
"TODO" comment) of WhatAnEgo.java
with the following.
System.out.print("Prof. "); System.out.print(args[0]); // args[0] should be a name System.out.print(" is the best!"); System.out.print("\n"); // '\n' is the newline char PictureFrame frame; // Done
but do not save the changes.
WhatAnEgo.java
?
WhatAnEgo.java
?
System.out.print()
.
public
is a visibility/accessibility modifier
in Java so, Eclipse presents it in a special color.
public
and delete the b
.
PictureFrame.java
and scroll
through the code. What do you notice immediately?
WhatAnEgo.java
tab.
System
.
What information appears?
out
.
What information appears?
frame
and
press Enter. Where is the cursor?
System.
(note the period). What happens?
o
(note that there is no period this time). What happens?
.
again. What happens?
Done
comment) that
declares a Color
object named highlight
.
highlight
.
import
statement.
WhatAnEgo.java
.
PictureFrame.java
doesn't contain setters because it
is immutable. However, we would like to add getters. To so so,
click on Source+Generate Getters and
Setters..... Then, click on Select Getters,
select "Generate methods comments", and click on Generate.
What happens?
PictureFrame
class says that the
toString()
method must return a String
containing the width, followed by "in. x ", followed by the height,
followed by "in.". If the matte is greater than 0, this must be
followed by " with a ", followed by the matte, followed by "in. matter".
Finally, if it has a stand, it should be followed by " (w/ stand").
Does the code that was generated by Eclipse satisfy the specification?
toString()
method generated by Eclipse with
the following.
/** * Return a human-readable String representation of this PictureFrame. * * @return The String representation */ public String toString() { String result; result = ""+width+"in. x "+height+"in."; if (matte > 0.0) result += " with a "+matte+"in. matte"; if (stand) result += " (w/ stand)"; return result; }
WhatAnEgo.java
.
WhatAnEgo.java
in the package explorer,
pull down to "Checkstyle", and over to "Check code with Checkstyle".
What happens?
/** * A very simple Java program that does nothing but generate * some output. * * @author Prof. Bernstein * @version 1.0 */
click on , and re-run Checkstyle. What happens?
/** * The entry point of the application. */
click on , and re-run Checkstyle. What happens?
* @param args The command-line arguments
and click on . What happens?
frame
.
What information appears?
System.out.print("I have a picture of him in a frame that is "); System.out.print(frame.toString()); System.out.print(".\n");
and click on . What happens?
PictureFrame
class?
frame
so that it is 8in x 10in with a 1in matte
and a stand. What code did you add?
PictureFrame.java
.
PictureFrame.java
.
PictureFrame.java
,
pull down to "Compare With", and over to "Local History...". What
happens?
PictureFrame.java
.
What happens?
args
in the
main()
method.
main()
?
Bernstein
in the "Program arguments" field.
Then click Run. What happens.
print()
method. However, you're not sure and
you don't want to re-type them if you don't have to. So, click and drag
to select all of those lines. What happens?
Copyright 2021