C Sc 227 Project: Four Main Methods

  1. With Eclipse, implement, run, and print a program in one of labs: A tutorial
  2. Complete three other programs (specifications given below).
  • In 228 or 930 Gould Simpson, login to your CS account on an Ubuntu machine (all but a few are running Ubuntu Linux)
  • In the login dialog box, enter your user name (most likely your UANetID)
  • The enter your password from a previous semester or use the randomly generated password emailed to you by
  • Click the Eclipse Icon(if not visible, go to ????
  • Eclipse will start and offer a Welcome page, which you should close (if it is visible)
  • Create a new Java project by clicking on File > New > Project
  • Make sure Java Project is selected, and then click the Next (at bottom)
  • Name your project with a name indicating the project such as 1_FourMainMethods
  • Create a class with File > New > Class

After Name: type the name of the class you want to create. For project 1, the first class

you create will be called Welcome. After you type that in, click Finish (at bottom).

· Type in the following code as it is shown below. As you type, you may encounter

squiggly red lines under portions of your code. This is the compiler telling you that you

may have an error. To be sure, type the entire line as shown below. For help, look at the

messages in the Tasks view under your program (or let the mouse hover over the error).

· Once everything is typed in, save the file by going to File > Save (or Ctrl-S for short).

Saving the file compiles the code into a class file and updates the error messages. Fix any

errors you may have before you go on.

· Next, go to Run >Run As > Java Application

· At the bottom of the screen in the Console box, you should see some output that says

Welcome. What is your name?

· Click on the console window to the right of this prompt

· Type in your name (input is green like Jane) and press the enter key

· The dialog should look like this (with a different name unless your name is Jane):

Welcome. What is your name? Jane

Hello Jane! I hope you are well :-)

· Print this program by selecting File > Print

· After printing and collecting Welcome.java from the printer (should have the CS watermark),

complete these other three problems.

2) Complete Grade Point Average (see grading criteria at the end)

Write a Java program that compute a student’s cumulative grade point average (GPA) for three

courses. Credits range from 0.5 to 15.0. Grades can be 0.0, 1.0, 2.0, 3.0, or 4.0. Test your

program by running it with several different inputs where you know the expected results. One

dialog must look like this:

Credits for course 1: 2.0

Grade for course 1: 2.0

Credits for course 2: 3.0

Grade for course 2: 4.0

Credits for course 3: 3.0

Grade for course 3: 4.0

GPA: 3.5

· Print out this file while in 228 or 930 GS (we need to see the C Sc watermark)

3) Complete Departure Times (see grading criteria at the end)

Write a Java program that reads in two different train departure times (where 0 is midnight, 0700 is 7:00

a.m., 13:14 is 14 minutes past 1:00 p.m., and 2200 is 10 p.m.) and displays the difference between the two

times in hours and minutes. The program should work even if the first departure time input is later in the

day than the second departure time input. Assume both times are on the same date and that both times are

valid. For example, 1099 is not a valid time because the last two digits are minutes, which should be in

the range of 00 through 59. 2401 is not valid because the hours (the first two digits) must be in the range

of 0 through 23 inclusive. Verify that your program works correctly by running it with a variety of valid

input, where you know the expected result. Here are three sample dialogs with the correct results (your

program needs to only generate one dialog for each program run):

Train A departs at: 1255

Train B departs at: 1305

0 hours and 10 minutes

Train A departs at: 2350

Train B departs at: 0055

22 hours and 55 minutes

Train A departs at: 0730

Train B departs at: 0845

1 hours and 15 minutes

· Print out this file while in 228 or 930 GS (we need to see the C Sc watermark)

4) Complete A Little Cryptography (see grading criteria at the end)

Write a Java program that hides a message in five words. Use one of the characters in the five

input strings to spell out one new word. A word of caution: The String charAt(int ) method

returns a character, but with + it is treated as if it were an int. So instead of concatenating five

characters, it could add up to the numeric equivalents used to store the characters. Consider the

following code that outputs 195 (97 for 'a' plus 98 for 'b'):

String aString = "ab";

System.out.println(aString.charAt(1) + aString.charAt(0)); // 195

Placing a string literal up front fixes the problem. This code

String aString = "abcde";

System.out.println("Secret message: " + aString.charAt(0) + aString.charAt(3));

generates the output Secret message: ad

So make sure you start your output with the label "Secret message: ". This forces the charAt return

value to become the characters you seek. Run your program with the following input and make up at least

one other message:

Enter five words: cheap energy can cause problems

Enter five integers: 4 2 1 0 5

Secret message: peace

· Print out this file while in 228 or 930 GS (we need to see the C Sc watermark)

Grading Criteria (subject to change)

Face to Face Sections 1, 2, and 3

___/ 8 You turned in a printout for each of the four problems and each printout appears

to compile and it is a worthy attempt to solve the problem

___/ 8 Each printout has the CS watermark indicating it was printed in the lab. (2pts each)

___/ 8 You have stapled or otherwise attached all three printouts together

___/ 8 Each printout has your name in a comment at the top of the file (2pts each)

___/ 8 Each file is formatted (use Ctrl+Shift+F or choose Source > Format) (2pts each)

___/ 60 Each problem is correct (15 points each)

Online Sections 6 and 910

___/ 24 You turned in an archive file with each of the four problems and each printout appears

to compile and it is a worthy attempt to solve the problem

To create an archive file from Eclipse

· Click on the Project Name

· Select File > Export > General > Archive File > Next

· Browse to a convenient location for storing the archive file (such as your Desktop)

· After Save As: enter a file name like 1_JaneDoe.zip (except with your name)

· Click Save and Finish

· Email the archive file as an attachment to: John McGowan t

___/ 8 Each file has your name in a comment at the top of the file (2pts each)

___/ 8 Each file is formatted (use Ctrl+Shift+F or choose Source > Format) (2pts each)

___/ 60 Each problem is correct (15 points each)