Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following class implementation (class Building). // class building

ID: 3695638 • Letter: C

Question

Complete the following class implementation (class Building). // class building public class Building { // Instance variables A string to hold the name of the building, // a double to hold the number of square feet in the building, // and an integer to hold the number of classrooms in the building. // Constructor to initialize the data fields. public Building(String theName, double theSquareFeet, int classRooms) { } // Reassign the variable holding the square footage of the building // a new value provided by the calling program. public void setNumberOfSquareFeet(double newSquareFootage) { } // Return the average square feet per classroom. public double averageRoomSize() { } // Return the first two characters of the building name as a string public String getAbbreviatedBuildingName() { } }

Explanation / Answer

Introduction

A method performs an assignment that completes the operations of a class. The methods we used in the previous sections relied on local variables to exchange information with other sections of the program. Sometimes, a method would need one or more values in order to carry its assignment. The particularity of such a value or such values is that another method that calls this one must supply the needed value(s). When a method needs a value to complete its assignment, such a value is called an argument.

Like a variable, an argument is represented by its type of value. For example, one method may need a character while another would need a string. Yet another method may require a decimal number. This means that the method or class that calls a method is responsible for supplying the right value, even though a method may have an mechanism of checking the validity of such a value.

The value supplied to a method is typed in the parentheses of the method and it is called an argument. In order to declare a method that takes an argument, you must specify its name and the argument between its parentheses. Because a method must specify the type of value it would need, the argument is represented by its data type and a name.

Suppose you want to define a method that displays the side length of a square. Since you would have to supply the length, you can start the method as follows:

In the body of the method, you may or may not use the value of the argument. Otherwise, you can manipulate the supplied value as you see fit. In this example, you can display the value of the argument as follows:

When calling a method that takes an argument, you must supply a value for the argument; otherwise you would receive an error. Also, you should/must supply the right value; otherwise, the method may not work as expected or it may produce an unreliable result. Here is an example:

Methods' Arguments

Introduction

A method performs an assignment that completes the operations of a class. The methods we used in the previous sections relied on local variables to exchange information with other sections of the program. Sometimes, a method would need one or more values in order to carry its assignment. The particularity of such a value or such values is that another method that calls this one must supply the needed value(s). When a method needs a value to complete its assignment, such a value is called an argument.

Like a variable, an argument is represented by its type of value. For example, one method may need a character while another would need a string. Yet another method may require a decimal number. This means that the method or class that calls a method is responsible for supplying the right value, even though a method may have an mechanism of checking the validity of such a value.

The value supplied to a method is typed in the parentheses of the method and it is called an argument. In order to declare a method that takes an argument, you must specify its name and the argument between its parentheses. Because a method must specify the type of value it would need, the argument is represented by its data type and a name.

Suppose you want to define a method that displays the side length of a square. Since you would have to supply the length, you can start the method as follows:

In the body of the method, you may or may not use the value of the argument. Otherwise, you can manipulate the supplied value as you see fit. In this example, you can display the value of the argument as follows:

When calling a method that takes an argument, you must supply a value for the argument; otherwise you would receive an error. Also, you should/must supply the right value; otherwise, the method may not work as expected or it may produce an unreliable result. Here is an example:

Passing an Argument by Value

When calling a methods that takes one or more arguments, we made sure we provided the necessary value. This is because an argument is always required and the calling method must provide a valid value when calling such a method. This technique is referred to as passing an argument by value.

Method Overloading

A typical program involves a great deal of names that represent variables and methods of various kinds. The compiler does not allow two variables to have the same name in the same method. Although two methods should have unique names in the same program, a class can have different methods with the same name if you follow some rules. The ability to havevarious methods with the same name in the same program is referred to as method overloading. To perform overloading, the methods must have different numbers or different type(s) of arguments.

The moment of inertia is the ability of a beam to resist bending. It is calculated with regard to the cross section of the beam. Because it depends on the type of section of the beam, its calculation also depends on the type of section of the beam. In this exercise, we will review different formulas used to calculate the moment of inertia. Since this exercise is fordemonstration purposes, you do not need to be a Science Engineering major to understan