Faculty of Computing and Information Systems
Fall Term 2011/1432-1433
Course Code: CPCS-202 Course Name: Programming I
________________________________________________________________
Problem 1:
Write a program that asks the user to enter a favorite color, a favorite food, a favorite animal, and the first name of a friend or relative. The program should then print the following two lines, with the user’s input replacing the items in italics: I had a dream that Name ate a Color Animal and said it tasted like Food!
For example, if the user entered blue for the color, hamburger for the food, dog for the animal, and Jake for the person’s name, the output would be
I had a dream that Jake ate a blue dog and said it tasted like hamburger!
Don’t forget to put the exclamation mark at the end.
Notes:
This project requires careful attention to spaces in output messages. In particular, a space must be explicitly printed between the variables color and animal.
Solution:
Problem Analysis Chart:
Given Data | Required Results | namecoloranimalfood | Print “I had a dream that Name ate a Color Animal and said it tasted like Food!" | Processing Required | Solution Alternatives | System.out.println("I had a dream that " + name + " ate a " + color + " " + animal); System.out.println("and said it tasted like " + food + "!"); | |
Algorithm:
1. Read Name from user. 2. Read Color from user. 3. Read Animal from user. 4. Read Food from user. 5. Display message “I had a dream that Name ate a Color Animal and said it tasted like Food!"
Sample Code Solution:
From now on to the end of your four year program here at the University, every program you submit whether it is in lab or as homework should include the following: * File name * Full description of the coded program * Author: Name of student * Student ID * Student email address * Date submitted
/** File name: