Methods with Input and Output (train)
CS 161 - Spring 2008

Due: Monday, February 11 at 10:00 pm.

Goals
- to use both the input and output streams
- to use methods with parameters

Overview
For this lab, you will write a Java program to draw a train picture sideways on the screen. The train has five cars total: an engine, a caboose, and three cars in the middle. The engine and caboose are just letters and wheels. For the three middle cars, each car has the same shape but is drawn with characters specified by the user. The train will look like the picture.

You must use a parameterized function that draws a single middle car with the user's specified edge and stripe. You may use a function to draw the engine and another to draw the caboose. Or, you may write one parameterized function that draws one of them and which you call twice. It is not necessary to use loops for this problem.

Input Specification
Each of the middle cars has a pair of input characters: an edge and a stripe. Draw the car's border with the edge character. Draw the inside stripe with the stripe character. The other features don't change from car to car.

Use six separate type String variables to hold the six input values. Each String will hold just one character for this program. Prompt for and read the characters before starting to print your train. You can use input.next() to read a String, where input is a Scanner. Order of input is important. The train picture shown results from the prompt and input (user types E s # $ = %)

   Please enter six whitespace separated characters for drawing the train
   Order is edge stripe edge stripe edge stripe
   E s # $ = %
Output Specification:
The output will look like the example picture. The edges of each car should be drawn with the user-specified edge character. It should be the predominant character. The stripe should be drawn with the stripe character. It should be an accent or decoration. You are free to be creative with the engine and caboose. The engine and caboose must exist and must be drawn with methods, but you will not lose points for having just boxes with wheels for the engine and caboose. Drawing the cars in the shape shown is acceptable.
      eeee
      eeee(o)
      eeee
      eeee
      eeee(o)
      eeee
         |
    EEEEEE
    E s  E(o)
    E s  E
    E s  E
    E s  E(o)
    EEEEEE
         |
    ######
    # $  #(o)
    # $  #
    # $  #
    # $  #(o)
    ######
         |
    ======
    = %  =(o)
    = %  =
    = %  =
    = %  =(o)
    ======
         |
      cccc
      cccc(o)
      cccc
      cccc
      cccc(o)
      cccc

Approaching the Problem
Start small basing your program on the rockets program in Chapter 1 of the textbook. Develop your solution incrementally. We suggest the following iterations although there are many ways to approach this problem. For each iteration, modify your source code, save, compile, and execute. Don't do too much in each iteration.

You absolutely must use methods for this assignment. The car function must take two String parameters specified by the user. You must call the car function three times with different variables as actual parameters. You must have a function to draw the engine and the caboose even if they just print boxes with wheels.

Delivery
When you are finished, submit your program as the train lab.