CSC 110: Fundamentals of Programming I Assignment #2: Static Methods, Scanners, for-loops Solved

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (2 votes)

Learning outcomes

When you have completed this assignment, you should understand:

  • How to evaluate expressions.
  • How to use a for-loop to repeat operations.
  • How to write and call a static method.
  • How to design, compile, run and check a simple and complete Java program on your own.
  • How to input data from the console.
  • How to use String methods.
  • How to indent and document a Java program.

 

 

             

Create a Java program named FoxSays.java. The program will request user input from the command line, and the program then “says” the text that is entered (in a quote box created with asterisks). The program will then print an ASCII fox. Below are two examples of the output from running FoxSays with the text the user enters underlined in red:

 

(Original ASCII fox art credit goes to Todd Vargo)

In your program, you will create two static methods:

  1. A static method called theMessage(), which does the following:
    1. Prompts the user to enter text (Print out: “What does the fox say?”).
    2. Creates and uses a Scanner object and its nextLine() method to read input from the user through the command-line interface.
    3. Uses the String’s length() method to determine the message’s size (the total number of characters in the String the fox says)
    4. Uses for-loops to create the appropriate sized quotation box around the fox’s message (the *’s above and below the message).

 

  1. A static method named printFox(), which should print out an ASCII fox:
    1. Remember your escape sequences to print out quotes (“) and backslashes (\).

 

Advice: Build this method in parts, compiling and running after each major addition to your code to check that the code does work as you expect. For example, you might first prompt the user to enter some text, then store the text as a string, and then directly print the text back. After that you might write theMessage() method and then, finally, add the necessary for loops.

 

File to submit: FoxSays.java

 

Marking

Your mark will be based on the following criteria:

  • Your code must compile and run. It must prompt the user, read text input, and produce the expected output as described and shown above.

 

  • Your code must conform to the requirements mentioned above (i.e., have theMessage() and printFox() methods, a Scanner object, for-loops, etc.).

 

  • Your code must follow the guidelines outlined in Style_Guidelines.pdf, found through the Lectures & Stuff link in the Lab Resources folder on connex.

 

  • CSc-110-Assignment-2.zip