Starting from:

$15

Lab Assignment #1 Activities Solution

1. Answer the following questions from Chapter 1 of your textbook. (10 points)
Question
Your Answer
What is the importance of the JVM? (2 points)
What is the Java source filename extension?
What is the Java bytecode filename extension?
What is the statement to display the message “Hello World” on the console? (2 points)
What is the Java statement to display the message “Hello World” in a GUI message dialog box? (2 points)
What is the command to compile a Java program?
CIS 2571: Introduction to Java
Lab Assignment
College of DuPage 2 CREngland
What is the command to run a Java program?
2. Answer the following questions from Chapter 2 of your textbook. Identify any needed import statements. (6 points)
Question
Your Answer
What is (are) the Java statement(s) to prompt the user to enter an input using a GUI dialog box? (4 points)
What is the Java statement to convert a string to an integer?
What is the Java statement to convert a string to a double?
3. Answer the questions in the spaces provided. Identify any needed import statements. (7 points)
Question
Your Answer
Identify the Java statements to properly create an input object connected to the console and read input data for a(n): (5 points)
• integer of the int type
• number of the float type
• string of text ending with whitespace
What is the Java statement used to cast a value of type float to an int?
What is the Java keyword used to identify a named constant?
CIS 2571: Introduction to Java
Lab Assignment
College of DuPage 3 CREngland
4. On your own, create a Java program to solve the Chapter 2 Programming Exercise 2.3 (Converting feet into meters) on page 75 of your textbook. Use an approach that gets input from the console and displays output to the console.
a. Create the source code file, Feet2Meters.java. Add a block comment at the top of the file to identify your name, file, date, class, assignment, and short description of the program. (8 points)
public class Feet2Meters {
public static void main(String[] args) {
// Enter foot
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a value for feet: ");
double feet = input.nextDouble();
double meter = feet * 0.305;
System.out.println(feet + " feet is " + meter + " meters");
}
}
b. Compile the source code until no errors are found. The Java bytecode file Feet2Meters.class should be created.
javac Feet2Meters.java
• Common Errors: http://www.cs.armstrong.edu/liang/intro9e/debug.html
• Setting the Environment Variable (See Section 1.3.1; our path is C:\Program Files\Java\jdk1.7.0_XX\bin): http://www.cs.armstrong.edu/liang/intro9e/supplement/Supplement1bInstallingJDK7.pdf
c. Run the Java bytecode and observe the results.
java Feet2Meters
d. Attach a printout of your source code.
e. Attach a printout of your sample output. (2 points)
Copying a Window to the Clipboard for Pasting and Printing
• Point and click the mouse to an active window (window you want to capture)
• Press "ALT + Prt SC"
• Open "WordPad" (Start, All Program, Accessories, WordPad) or “MS-Word” (Start, All Program, Microsoft Office, Microsoft Word)
• Choose Edit, and click on Paste. (Now the window should appear on your document)
• Hit <Return Key to go to new line.
• Save it into a file and print it out.
CIS 2571: Introduction to Java
Lab Assignment
College of DuPage 4 CREngland
5. On your own, create a Java program to solve the Chapter 2 Programming Exercise 2.3 (Converting feet into meters) on page 75 of your textbook. Use an approach that gets input from a dialog box and displays output in a dialog box.
a. Create the source code file, GUIFeet2Meters.java. Add a block comment at the top of the file to identify your name, file, date, class, assignment, and short description of the program. (12 points)
b. Compile the source code until no errors are found. The Java bytecode file GUIFeet2Meters.class should be created.
javac GUIFeet2Meters.java
• Common Errors: http://www.cs.armstrong.edu/liang/intro9e/debug.html
• Setting the Environment Variable (See Section 1.3.1; our path is C:\Program Files\Java\jdk1.7.0_XX\bin): http://www.cs.armstrong.edu/liang/intro9e/supplement/Supplement1bInstallingJDK7.pdf
c. Run the Java bytecode and observe the results.
java GUIFeet2Meters
d. Attach a printout of your source code.
e. Attach a printout of your sample output. (5 points)
Copying a Window to the Clipboard for Pasting and Printing
• Point and click the mouse to an active window (window you want to capture)
• Press "ALT + Prt SC"
• Open "WordPad" (Start, All Program, Accessories, WordPad) or “MS-Word” (Start, All Program, Microsoft Office, Microsoft Word)
• Choose Edit, and click on Paste. (Now the window should appear on your document)
• Hit <Return Key to go to new line.
• Save it into a file and print it out.

More products