Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Preliminaries Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab5DavidLiu Create an Eclipse Java Project. Add a Java class

Preliminaries

Create a project submission folder, in the form Lab#FirstNameLastName. For example, mine would be Lab5DavidLiu

Create an Eclipse Java Project.

Add a Java class named PatternMaker to your project

Exercises

Part 1) For Loop and Pattern Set up 14 points

The majority of the points come from setting up the lab to print patterns appropriately based on user input. (a) Declare variables to store the following information

(a.1) The type of pattern the user wants (a String)

(a.2) The amount of lines the user wants in the pattern (an int), numLines

(b) Ask the user the pattern they want. It should be either square or rectangle (no

quotes)

(c) Ask the user for the amount of lines they want.

(d) Use the method of your choice (if-elseif-else block or a switch statement) to

determine which pattern the user chose. If neither square or rectangle was entered, tell

the user to buzz off and end the program.

(e) If the pattern input is rectangle, print out a three wide rectangle of a symbol of your choice (such as *,#, or $) that is numLines lines long using a for loop to print that number of lines. (That is, run the loop from 0 to numLines).

(f) If the pattern input is for square, print out a numLines by numLines square of a symbol of your choice. This will required the use of print and nested for loops (a for loop for square width and a for loop for square height). Note that the outermost loop (the one that controls height) should print the newlines and the innermost loop (the one that controls width for each new row) should print symbols.

Sample input and output follows:

What pattern: rectangle

How many lines: 5

$$$

$$$

$$$

$$$

$$$

---

What pattern: square

How many lines: 2

**

**

---

What pattern: fish

How many lines: 25

You offend me, sir! The program is now done.

Part 2) File Time 6 points

This part of the lab changes Part 1 to use output files

Make a new object, a PrintWriter object that opens the output file Pattern.txt.

For the square and rectangle inputs, write the output to the file using PrintWriter rather than using console output

For the third case, where the program is offended, do not change the results

At the very end of the code, before the end of the main method, close the PrintWriter (and while youre at it, close the Scanner too!) with the .close() method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago