Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following java program displays the drawing of a scalable tower whose size is determined by user input. import java.util.Scanner; public class Tower { public

The following java program displays the drawing of a scalable tower whose size is determined by user input. 

import java.util.Scanner;

public class Tower { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int size = scnr.nextInt();

drawTower(size); }

public static void drawLine(int size) { for (int i = 1; i <= size * 10 - 1; i++) { System.out.print("X"); } System.out.println(); }

public static void drawPillars(int size) { for (int i = 1; i <= size; i++) { System.out.print(" XXX"); for (int j = 1; j <= (size * 10 - 1) / 3 - 4; j++) { System.out.print(" \\"); } System.out.print(" XXX"); System.out.println(); } }

public static void drawLevel(int size) { for (int i = 1; i <= size; i++) {

System.out.print(" XXX"); for (int j = 1; j < size; j++) { System.out.print(" \\ \\ XXX"); } System.out.println(); } }

public static void drawBase(int size) { for (int i = 1; i <= size + 1; i++) { for (int j = 1; j <= size * 10 - 1; j++) { System.out.print("X"); } System.out.println(); } }

public static void drawTower(int size) { drawLine(size); drawPillars(size); for (int i = 1; i <= size; i++) { drawLine(size); drawLevel(size); } drawBase(size); } }

sample run: when userInput = 3

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ \ \ \ XXX XXX \ \ \ \ \ XXX XXX \ \ \ \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Question: Add a method called "int doTheLean (int space)" to make the tower leaning. Every row leans one space more than the row above it. This method prints a bunch of blank spaces in a for loop, and anyone who needs to have spaces printed simply calls the method and it does the job. Initialize the variable space to 0 in the main, and before the doTheLean() method ends, increment space by 1 and return the updated value to its calling method. In this way the calling method knows the updated value of spaces for the next time it calls doTheLean.

sample run: when userInput = 3

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ \ \ \ XXX XXX \ \ \ \ \ XXX XXX \ \ \ \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXX \ \ XXX \ \ XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

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

Step: 3

blur-text-image

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

10-4 How to improve the tone of negative messages.

Answered: 1 week ago