Part 2) File Time This part of the lab changes Part 1 to use output files (a) Make a new object, a Print Writer object that opens the output file "Pattern.txt". (b) For the square and rectangle inputs, write the output to the file using Print Writer rather than using console output (c) For the third case, where the program is offended, do not change the results, not writing to the file. (d) At the very end of the code, before the end of the main method, close the PrintWriter (and while you're at it, close the Scanner too!) with the .close() method.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Can someone please help me to write the following program ONLY PART 2 using Java eclipse.
Exercises
Part 1) - For Loop and Pattern Set up -
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.
Transcribed Image Text:Exercises Part 1) - For Loop and Pattern Set up - 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 require 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
This part of the lab changes Part 1 to use output files
(a) Make a new object, a Print Writer object that opens the output file "Pattern.txt".
(b) For the square and rectangle inputs, write the output to the file using Print Writer
rather than using console output
(c) For the third case, where the program is offended, do not change the results, not
writing to the file.
(d) At the very end of the code, before the end of the main method, close the Print Writer
(and while you're at it, close the Scanner too!) with the .close() method.
Transcribed Image Text:(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 require 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 This part of the lab changes Part 1 to use output files (a) Make a new object, a Print Writer object that opens the output file "Pattern.txt". (b) For the square and rectangle inputs, write the output to the file using Print Writer rather than using console output (c) For the third case, where the program is offended, do not change the results, not writing to the file. (d) At the very end of the code, before the end of the main method, close the Print Writer (and while you're at it, close the Scanner too!) with the .close() method.
Expert Solution
steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education