Lab 4: Using Java Classes 



Lab 4 Due Date: Wednesday October 3 at 11:59 pm


Background:

Lab 4 will be an exercise in using Java classes and in writing your first Java applications. You will modify the NameInitials.zip demo project so that the user will enter the first, middle, and last name from the keyboard as one string, and then display the three initials in lower case as the demo currently does. The second project will have you enter a four word phrase from the keyboard and build a String object of the four words in reverse order to display.

Lab 4a: Modify Name Initials Demo

Download the lab4.zip file. Save the zip file to your C:\Temp directory and unzip the files. Open the directory NameInitials. You should see the following files:
  • NameInitials.mcp (the project file for this Java application)
  • NameInitials.java (the source file for this Java application)
Open the NameInitials.mcp file and look at the filenames listed inside. NameInitials.mcp is not a Karel or Java program file - it s project file CodeWarrier requires as part of every Java program. A project file keeps track of what files are part of a Java program. Typically there is one project file for each Java program -- however there can be many Java source files comprising a single Java program. The program we are going to work with today only has 1 source file:    NameInitials.java.
The task
The user will enter a first, middle, and last name from the keyboard as a single String object. Using the appropriate String methods (including indexOf(); see the API), the program will get the first initial from each name and make a new string of the initials, to be displayed.

Modifying the Name Initial program

For this exercise, all of your work will be done in NameInitial.java. You must modify the code in NameInitial.java .  You only have to modify the existing main() method to solve the problem. Do not change any of the code that is currently in NameInitial.java. Comments in the file indicate what and where the modifications should be made.

 

Lab 4b: Reverse a String

Inside the lab2 directory, you will see the directory ReverseString. Open it. You should see the following files:
  • ReverseString.mcp (the project file for this Java application)
  • ReverseString.java (the source file for this Java application)
Open the ReverseString.mcp file and look at the filenames listed inside. You will see that ReverseString.java is included as part of this project.

Go to the top of the project window and select Project / Run or click the small arrow head (looks like the Play button on a VCR / DVD player) in the middle of the project window menu bar. You will see that essentially nothing happens.

The task
The user will be prompted to enter a four word phrase from the keyboard, to be read as a single string,

  i.e. How now brown cow

The user will use the appropriate String methods, to build another single String with the words in reverse order, to be displayed

  i.e. cow brown now How

A solution in which the user enters four different String objects from the keyboard, and displays them in reverse order without parsing a single String and building a single string will receieve no credit for this problem.

Design
Use the appropriate String member functions to solve this problem. Your entire solution will be written in the main() method of the ReverseString class.


Handing in your Solution

Your solutions should be in the form of .zip files. When we grade your solution we will unzip the folder and execute the project. If your project does not run you will lose the execution points for that lab.

Your Solution zip file must contain all the files in your projects

Your teaching assistants will show you how to zip up the files for submission. Instructions are also in the Tutorial document that is available
 

Click on this link to Submit your zip file