MrLamont.com

  • Home
  • Student Information
  • ICS3CI-01
    • Marks
    • Pursuing a Programming Career >
      • Post-Secondary Education
      • Assignment
    • Unit 1 - Basic Drawing >
      • The Coordinate System
      • Basic Drawing Commands
      • Adding Colour
    • Unit 2 - Basic Animations >
      • Flowcharting
      • If, Else if, and Else Statements
    • Unit 3: Human Interaction
    • Unit 4: Creating Methods
    • Unit 5: For Loops >
      • Sample drawings to Try
    • Unit 6: Arrays
    • Final Project (30%)
    • EXTRA - Classes and Objects
  • ICS3UI
    • Hand In List
    • GitHub Info
    • Self Evaluation
    • Marks
    • Classroom Repository
    • Unit 2: Making Decisions - If and While >
      • Branching With If
      • Using While Loops
      • Nesting Statements
      • Flowcharting
      • Exercise 2
      • Quiz 2
    • Unit 3: Counting Loops and More Decisions >
      • Variables
      • The For Loop
      • Exercise 3
      • Quiz 3
    • Unit 4: Basic Input/Output >
      • Your First Program
      • Output to the Screen
      • Getting User Input
      • Exercise 4 - Input, Output, Variables
    • Unit 5 - Fun with Java Strings >
      • String Methods
      • Exercise 5 - Translator
    • Unit 6 - Java Methods >
      • Anatomy of a Method
      • Creating Your Own Methods
      • Exercise 6 - Methods
    • Unit 7 - 1D Arrays >
      • Arrays
      • Exercise 7 - Arrays
    • Unit 8 - 2D Graphics >
      • Flappy Bird Assets
      • Basic Game Class
      • The Graphics Class
      • Get Things Moving!
      • Exercise 8 - Clown Face
    • Final Project (30%)
  • Interesting Links
    • Programming Club
    • Game Design
    • Game Programming
    • How it Works
  • Home
  • Student Information
  • ICS3CI-01
    • Marks
    • Pursuing a Programming Career >
      • Post-Secondary Education
      • Assignment
    • Unit 1 - Basic Drawing >
      • The Coordinate System
      • Basic Drawing Commands
      • Adding Colour
    • Unit 2 - Basic Animations >
      • Flowcharting
      • If, Else if, and Else Statements
    • Unit 3: Human Interaction
    • Unit 4: Creating Methods
    • Unit 5: For Loops >
      • Sample drawings to Try
    • Unit 6: Arrays
    • Final Project (30%)
    • EXTRA - Classes and Objects
  • ICS3UI
    • Hand In List
    • GitHub Info
    • Self Evaluation
    • Marks
    • Classroom Repository
    • Unit 2: Making Decisions - If and While >
      • Branching With If
      • Using While Loops
      • Nesting Statements
      • Flowcharting
      • Exercise 2
      • Quiz 2
    • Unit 3: Counting Loops and More Decisions >
      • Variables
      • The For Loop
      • Exercise 3
      • Quiz 3
    • Unit 4: Basic Input/Output >
      • Your First Program
      • Output to the Screen
      • Getting User Input
      • Exercise 4 - Input, Output, Variables
    • Unit 5 - Fun with Java Strings >
      • String Methods
      • Exercise 5 - Translator
    • Unit 6 - Java Methods >
      • Anatomy of a Method
      • Creating Your Own Methods
      • Exercise 6 - Methods
    • Unit 7 - 1D Arrays >
      • Arrays
      • Exercise 7 - Arrays
    • Unit 8 - 2D Graphics >
      • Flappy Bird Assets
      • Basic Game Class
      • The Graphics Class
      • Get Things Moving!
      • Exercise 8 - Clown Face
    • Final Project (30%)
  • Interesting Links
    • Programming Club
    • Game Design
    • Game Programming
    • How it Works

Exercise 4 - For Loops

Create a project called Assignment4 and place all questions inside of this project.


Question 1
Redo Question 1 from exercise 3, the count down question, but instead of using a while loop, use a for loop. Name your program Question1

Example Output
10
9
8
7
6
5
4
3
2
1
0
Blast Off!


Question 2
Write a program that will ask the user for a message and the number of times they want that message displayed. Then output the message that number of times. Name your program Question2

Example Output
What message would you like displayed?   I Like Cake
How many times would you like to display your message?    4
I Like Cake
I Like Cake
I Like Cake
I Like Cake




Question 3
Create a program that will ask the user for a number and then print out a list of number from 1 to the number entered and the square of the number. Name your program Question3


Example Output
What number would you like to go up to?    5
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
5 squared is 25



Question 4
Write a program to output a backwards count by 5s from 100 down a number between 100 and 50 that is input before the countdown begins. The program should stop when the count would be greater than the number input. Name your program Question4

Example Output
Enter a number between 50 and 100 to stop at:  82
100
 95
 90
 85




Question 5
When $1000 is deposited at 5 percent simple interest, the amount grows by $50 each year (i.e. the interest is calculated on the original principal of $1000 only every time). When money is invested at 5 percent compound interest, then the amount at the end of the year is 1.05 times the amount at the beginning of that year. Write a program to display the amounts for 10 years for a $1000 deposit at 5 percent simple and compound interest. The first few lines displayed in the picture box should appear as shown below. Save your program as Question5.

                                                Amount                        Amount
                                                Simple                         Compound
                        Year                Interest                        Interest
                        1                      $1,050.00                    $1,050.00
                        2                      $1,100.00                    $1,102.50
                        3                      $1,150.00                    $1,157.63



Question 6
Rewrite problem 5 so that the user can enter their own starting principal, their own interest rate and the number of years that they want displayed on the screen. At the end display a grand total for each column. Save this program as Question6.



Question 7
Write a program that will request a number in the range 1 to 20 and display a row of that many stars (asterisks).  Hint: when you print, you can tell Java not to put any spaces between this line, and the next line by using the print() command instead of println(). For instance,
System.out.print("Hello ");
System.out.println("World");
will output to the screen "Hello World" all on one line.
Name your program Question7

Example Output
Please enter the number of stars you would like(between 1 and 20):   6
* * * * * *



Question 8
Modify question 7 so that when the user enters a number, the output is a square of stars instead of a line. For this, you will need to use nested for loops (one for loop inside of another for loop). Name your program Question8

Example Output
Please enter the number of stars you would like(between 1 and 20):   6
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *

Powered by
✕