Question: What this Lab Is About: Classes and objects Familiarization with default or no-argument constructor and constructor with arguments. Defining void methods and return value methods.

What this Lab Is About: Classes and objects Familiarization with default or no-argument constructor and constructor with arguments. Defining void methods and return value methods. Use the following Coding Guidelines: When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem Description: For this Lab you have to implement a class Builder. Builder class should have instance variable name. For Builder class, supply a constructor and the following methods: getName(),makeRow(int n, String s), makePyramid(int n, String s). Step 1: Getting Started. Download a class called Lab7. Be sure to name your file Lab7.java 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: your own description of the program. // FOR: CSE 110- Lab #7 // TIME SPENT: how long it took you to complete the assignment. //-----------------------------------------------------------*/ Step 2: Create a Separate class Builder.java. Declaring Class Examining the problem, we need to create a Builder class, declare Builder class as follows public class Builder{ } Inside the class, declare a variable: an string variable called name. // declare some variables of different types: // an String called name Step 3: Defining the constructors: Remember the constructor with arguments assigns input data to the data members. public Builder (String name) { // write the segment of code //that assigns input data to the data members } Step4: Supply the methods You need to supply the following get methods: getName () to get the Name of the Builder object. Hint: These method contains a line of code that returns the desired variable value(id, major...). public String getlName() { // write a line of code //that returns the name } You should have a makeRow method. Given an integer n and string s, the method returns an other string that have n copies of s in one row. Method should return a string. 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 makePyramid that given an odd integer n and a String s, prints a pyramidal shape using s. The top of the pyramid has a single copy of s, and each successive row has two additional copies of s. The last row contains n copies of s. For example, calling makePyramid(7, "*"); prints the following lines: ---*--- --***-- -*****- ******* public void makePyramid(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. To use Builder class variables and methods we need to have a runner function. For any class in java, main method will be the running method. Your class Lab7 will have the main method. To use the Builder class variables and methods, you need to use the constructor to create an object of Builder Class. 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 --> // Create a brand-new builder with a given name using our Builder.java class // called myBuilder using the variable // name provided by the user --> } } Hint: Do not forget to import the Scanner package at the very top of your program: import java.util.Scanner; Step 5: Calling Builder class methods and display the output The methods in the Builder class will 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, representing number of stars in the base of a pyramid :"); // Using the Builder method makePyramid and integer t, print pyramid with * as a string // s. --> Step 7: Display the output See the sample output below and make sure to display is the same format. Sample Output: Below is an example of what your output should roughly look like when this lab is completed. All text in bold represents user input Name of the builder: Alex The name of builder is: Alex Enter a positive integer: 5 =====*****===== Enter a positive odd integer, representing number of stars in the base of a pyramid : 7 ---*--- --***-- -*****- ******* Second run: Name of the builder: Bob The name of builder is: Bob Enter a positive integer: 9 =========*********========= Enter a positive odd integer, representing number of stars in the base of a pyramid : 21 ----------*---------- ---------***--------- --------*****-------- -------*******------- ------*********------ -----***********----- ----*************---- ---***************--- --*****************-- -*******************- *********************

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!