CSCI-1320 Homework 09: I Will Finish My P1 Homework... I Will Finish My P1 Homework...

Instructor: Todd Dole

Purpose Statement

This assignment makes use of a common form of loop in which the loop body is iterated a fixed number of times. By "fixed" we mean that the number of iterations (repeats) is known prior to beginning the loop. When you finish the assignment it would be good to take time to use the debugger to observe the behavior of the program and to watch the values of variables as each step completes.

Instructions

As you may know from having watched episodes of “The Simpsons”, Bart often gets into trouble at school and is required to write sentences over and over again on the chalk board. Your assignment is to construct an program that will write a message over and over again for Bart (given a sentence and the number of times the sentence should be written).

Your program should allow the user to enter a sentence and how many times the sentence should be displayed. The output, of course, will be the sentence however many times the user requested it. The statements below illustrate how to declare, read, and display a sentence:

  public static void main(String [] args)
  {
    Scanner scan= new Scanner(System.in);
    String msg;
    System.out.print("Enter message: ");
    msg= scan.nextLine();
    System.out.println(msg);
  }

NOTE: For this program, have the user enter the sentence before they enter the number of times they want to display the sentence. We'll investigate why later. Name your class RepeatMessage, and upload your RepeatMessage.java source code file to the assignment in Canvas.