Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description: ASU Home My ASU Colleg For this Lab you have to implement a class Builder. Your Builder class should have instance variable name.,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Problem Description: ASU Home My ASU Colleg For this Lab you have to implement a class Builder. Your Builder class should have instance variable name., Supply a constructor method for your Builder class and the following methods: getName(), makeRow(int n, String s), printPyramid(int n, String s). Step 1: Getting Started Create a class called Lab7. Use the same setup for setting up your class and main method as you did in previous labs and assignments. Be sure to name your file Lab7.java. Assignment Documentation: At the beginning of each programming assignment you must have a comment block with the following information: // --------- // AUTHOR: your name // FILENAME: title of the source file // SPECIFICATION: description of the program // FOR: CSE 110- Lab #7 // TIME SPENT: how long it took you to complete the assignment 77--------------------------------------------------------- Step 2: Create a Separate Builder.java file and define a Builder Class Examining the problem, we need to create a Builder class, declare Builder class as follows public class Builder { Inside the Builder class declare a String variable called name Step 3: Defining the constructors: ASU Home My ASU Colleg Remember that the purpose of a constructor is to assign valid values to all the data members. public Builder (String name) { // write the segment of code // that assigns the parameter value to the private instance variable Step4: Supply the methods Implement the getName method: Hint: getter methods often simply return the desired value, which is usually stored in a private instance variable. public String getName() { // write a line of code that returns the name Implement a makeRow method. Given an integer n and string s, the makeRow method returns an other String that has n copies of s in a row. For eaxmple makeRow(5, "abc") should return "abcabcabcabcabc". public String makeRow(int n, String s) { // Given an int n and string s, // return a string that represents n copies of s in one row. //Example: n = 5, s = "*", return a string "*****" Write a method called printPyramid that given an odd integer n and a string s, prints (not returns) a pyramidal shape made out of that string s. The top of the pyramid has a single copy of s, and each successive row has ASU Home My ASU Colleg public void printPyramid(int n, String s) { // Make use of makeRow method and System.out.println // to print the pyramid. // note this method does not return anything. Step 5: Calling the constructor of Builder class from the "main" method. In your Lab7.java file, you will instantiate and use a Builder class object. import java.util.Scanner; public class Lab7 { public static void main(String[] args) { //declare variables where you will store inputs from user --> // declare a Scanner object --> // prompt the user for input string name --> // store the input in the declared variables --> // declare a variable of type Builder named myBuilder // and instantiate a brand-new builder object // with the name given by the user above --> ASU Home My ASUColleges Hint: Do not forget to import the Scanner package at the very top of your program. Step 6: Calling Builder class methods and display the output Now (also in the main method) we will call the methods in the Builder class to display the required outputs. // call the getName() method to get the name of the builder. --> // Ask for integer n from user using Scanner class System.out.println("Enter a positive integer:"); // Using your builder's makeRow method print a string below, // Example: =====*****===== with n = 5; --> // Ask for odd integer t from user using Scanner class System.out.println("Enter a positive odd integer :"); // Call the Builder method printPyramid, passing t and "*" as the arguments // to print pyramid with "*" as a string. --> Step 7: Sample Output Below is an example of what your output should roughly look like when this lab is completed. All text in bold red represents user input. First run: Name of the builder: Alex The name of builder is : Alex Enter a positive integer :5 Step 7: Sample Output ASU Home My ASU Colleges Below is an example of what your output should roughly look like when this lab is completed. All text in bold red represents user input. First run: Name of the builder: Alex The name of builder is : Alex Enter a positive integer :5 =====*****===== Enter a positive odd integer :7 : * Second run: Name of the builder: Bob The name of builder is : Bob Enter a positive integer :3 ===***=== Enter a positive odd integer : 11 ** * * * * X ASU Home My ASU College * X * X Second run: Name of the builder: Bob The name of builder is : Bob Enter a positive integer :3 ===***=== Enter a positive odd integer : 11 * * * * * * * * * * *

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions