Labs

Labs come with solutions that are related to this section's name. Solutions for these labs are in simpleprograms/solutions.

For organizing the labs add a labs folder inside the simpleprograms folder. You can create all your new classes in this simpleprograms/labs folder.

It is a good idea to name your program file the same as the solution. It's also helpful to copy-paste the lab instructions into a comment in the program, so you know what it does.

For example, you would write lab 1 in a file called HelloName.java, and inside that file add the comment

/*
Change the "Hello, world!" program to print "Hello, " followed by your first name. Compile and run your modified program.
*/

The solution for HelloName.java is simpleprograms/solutions/HelloName.java

  1. Change the "Hello, world!" program to print "Hello, " followed by your first name. Compile and run your modified program.

(Solution: HelloName.java)

  1. Change the "Hello, world!" program again to use separate System.out.println(...) calls to print "Hello," followed by your first name on two different lines.

Compile and run it again (in fact, in each lab exercise from now on, compile and run your program after making the given change).

(Solution: TwoPrints.java)

  1. Change the "Hello, world!" program again by inserting one or more \t in the beginning of one of the character strings being printed and look for any differences in the output.

(Solution: HelloTabs.java)

  1. Change the "Hello, world!" program yet again. Have it print a row of asterisks above the text and another line of asterisks below.

Add an asterisk at the beginning and the end of each line of the message itself. Experiment using spaces and tabs, and see if you can get the message to appear in the center of a box made up of asterisks.

(Solution: HelloStars.java)

  1. Write a new program that prints the following on the screen:
     Testing ...
       ... 1 ...
         ... 2 ...
           ... 3 ...
    
    Can this program be written with one System.out.println(...) call? ... with more than one?

(Solution: Testing123.java)

You will find that the labs in this workbook contain more exercises than can be completed during a normal lab session in class. There are several reasons for this: * To provide a selection of exercises from which you can choose. * To leave many exercises you can work on in your own time, at work or at home. * To provide additional challenges for students who already have some programming experience.

So, don't worry if you don't finish all, or even most, of the labs in the time available during class. Just start at the beginning and keep working until the lab session is over.


Prev -- Up -- Next