Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

, you will write a complete class called SquaresCubes in a file called SquaresCubes.java and upload the file . This class should have the following

  1. , you will write a complete class called SquaresCubes in a file called SquaresCubes.java and upload the file. This class should have the following methods :
    1. padString that accepts two parameters: a String and an integer representing a length. The method should pad the parameter string with spaces until its length is the given length. (This is exactly the method you wrote for Exercise 3.17 from Practice-It! website already. Copy that code here)

    2. printSquaresCubes that accepts two integers as parameters: a starting number and an ending number. This method should calculate and print the squares and cubes of all the numbers between the starting and ending numbers (both included) in a tabular form as shown below. Use column width=10 for each column plus a single separator space between the columns when you format the table. Use the padString method to get the numbers and titles aligned in the table as shown below.
    3. main method that calls the printSquaresCubes method twice: once with 5 and 10 as the starting and ending numbers respectively, and next with 100 and 110 as the starting and ending numbers respectively. main method shouldn't have any print statements. It only has two calls to the printSquaresCubes method.

Here's a sample run output:

image text in transcribed

3.17

image text in transcribed

Starting Number: 5 Ending Number: 10 ========== ========== Number Squared ========== ========== 25 36 ========== Cubed ========== 125 216 343 512 729 1000 49 64 ========== 81 100 ========== ========== Starting Number: 100 Ending Number: 110 ========== ========== Number Squared ========== ========== 100 10000 101 10201 102 10404 103 10609 10816 105 11025 106 11236 107 11449 108 11664 109 11881 110 12100 ========== Cubed ========== 1000000 1030301 1061208 1092727 1124864 1157625 1191016 1225043 1259712 1295029 1331000 104 ========== ========== Show Header BJP5 Exercise 3.17: padString Language/Type: Author: $ Java method basics parameters return Strings Roy McElmurry (on 2019/09/19) Write a method padString that accepts two parameters: a String and an integer representing a length. The method should pad the parameter string with spaces until its length is the given length. For example, padString("hello", 8) should return" hello". (This sort of method is useful when trying to print output that lines up horizontally.) If the string's length is already at least as long as the length parameter, your method should return the original string. For example, padString("congratulations", 10) would return "congratulations". Type your solution here: 1 public static String padString (String word, int totalLength) { 2 int len=word. length(); 3 if (totalLength

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

More Books

Students also viewed these Databases questions

Question

Does your message present a conclusion?

Answered: 1 week ago