Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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); } }

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

Question:

The java program above prints a scalable tower. Based on the program, add a method to make the tower leaning. Every row leans one space more than the row above it.

Sample run:

Enter the size: 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_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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions