Answered You can hire a professional tutor to get the answer.

QUESTION

Create a class named Sandwich. Data fields include a String for the main ingredient (such as "tuna"), a String for bread type (such as "wheat"), and...

11. a. Create a class named Sandwich. Data fields include a String for the main

ingredient (such as "tuna"), a String for bread type (such as "wheat"), and a

double for price (such as 4.99). Include methods to get and set values for each of

these fields. Save the class as Sandwich.java.

b. Create an application named TestSandwich that instantiates one Sandwich object

and demonstrates the use of the set and get methods. Save this application as

TestSandwich.java.

12. a. Create a class named Student. A Student has fields for an ID number, number of

credit hours earned, and number of points earned. (For example, many schools

compute grade point averages based on a scale of 4, so a three-credit-hour class in

which a student earns an A is worth 12 points.) Include methods to assign values

to all fields. A Student also has a field for grade point average. Include a method to

compute the grade point average field by dividing points by credit hours earned.

Write methods to display the values in each Student field. 

Save this class as Student.java.

b. Write a class named ShowStudent that instantiates a Student object from the

class you created and assign values to its fields. Compute the Student grade point

average, and then display all the values associated with the Student. Save the

application as ShowStudent.java.

c. Create a constructor for the Student class you created. The constructor should

initialize each Student's ID number to 9999, his or her points earned to 12, and

credit hours to 3 (resulting in a grade point average of 4.0). Write a program that

demonstrates that the constructor works by instantiating an object and displaying

the initial values. Save the application as ShowStudent2.java.

13. a. Create a class named Lease with fields that hold an apartment tenant's name,

apartment number, monthly rent amount, and term of the lease in months. Include

a constructor that initializes the name to "XXX", the apartment number to 0, the

rent to 1000, and the term to 12. Also include methods to get and set each of the

fields. Include a nonstatic method named addPetFee() that adds $10 to the

monthly rent value and calls a static method named explainPetPolicy() that

explains the pet fee. Save the class as Lease.java.

b. Create a class named TestLease whose main() method declares four Lease

objects. Call a getData() method three times. Within the method, prompt a user

for values for each field for a Lease, and return a Lease object to the main()

method where it is assigned to one of main()'s Lease objects. Do not prompt the

user for values for the fourth Lease object, but let it continue to hold the default

values. Then, in main(), pass one of the Lease objects to a showValues() method

that displays the data. Then call the addPetFee() method using the passed Lease

object and confirm that the fee explanation statement is displayed. Next, call the

showValues() method for the Lease object again and confirm that the pet fee has

been added to the rent. Finally, call the showValues() method with each of the other

three objects; confirm that two hold the values you supplied as input and one holds

the constructor default values. Save the application as TestLease.java.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question