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:
JMUConsole class (used in this lab) is an easy way to
send output to the console. It is used as follows:
JMUConsole.open() once before the
program generates any output.JMUConsole.print() one or more times,
passing it a single argument (i.e., the thing to display
on the console).JMUConsole.close() once before the program
terminates.
For those people who know how to use them, it also has
static printf() and println() methods.
. (How you do this will depend on your
operating system and how/where you installed jGRASP.)
WhatAnEgo.java by clicking on File-
Open, navigating to the appropriate directory/folder,
and selecting the appropriate file.
to compile
WhatAnEgo.java (i.e., to create
a file named WhatAnEgo.class containing
equivalent byte codes).
to run
this file.
print to prnt.
WhatAnEgo.java.
WhatAnEgo.java could
not be compiled because it contains a syntax error. There is a
number after the text WhatAnEgo.java and between two
colons. What do you think this number indicates?
cannot find symbol. What do you think this means?
prnt that is passed a String and
that the compiler does not think there is such a function. The
next line contains the statement containing the problem. Under
that is a line with a ^ (called a caret). What is the caret
pointing at and why?
prnt back to print.
WhatAnEgo.java. (It should compile properly.)
WhatAnEgo.java, and make sure you can interpret the
error messages. When you are done, change everything back so that
the program compiles correctly.
size to 0 and save the file.
WhatAnEgo.
WhatAnEgo.java caused the run-time error?
1100
and save the file.
550 is assigned to
rank, save it, re-compile it, and re-execute it.
/**
* A very simple Java program that does nothing but generate
* some output.
*
* @author Prof. David Bernstein, James Madison University
* @version 2.0
*/
public class WhatAnEgo {
/**
* The entry point of the application.
*
* @param args The command-line arguments. args[0] should be a name
*/
public static void main(String[] args) {
int percentage;
int rank;
int size;
size = 1100;
rank = 1;
percentage = (1 - (rank / size)) * 100;
JMUConsole.open();
JMUConsole.print("Prof. Bernstein is ranked ");
JMUConsole.print(percentage);
JMUConsole.print(" percent.\n");
JMUConsole.print("He's great!\n");
JMUConsole.close();
// Done
}
}
Copyright 2020