class called Lamp

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 5RQ
icon
Related questions
Question

1. Complete the code for the class called Lamp that models a lamp’s attributes and behaviors. The Lamp object has a private attribute called lamp_on, that models the state of the lamp. The lamp_on is set to true when the state of the map is ‘on’ and lamp_on is set to false when the state of the lamp is ‘off’.
The Lamp object can have two behaviors/methods –1) setLampOn() that sets the value/state of lamp_on to true; 2) setLampOff() that sets the value/state of lamp_on to false.
The Lamp class has a default constructor that sets the default value of lamp_on to false.
The Lamp class has getters and setters for the instance variable.

2. Continue along problem 1) and write a statement to create a Lamp object using the default constructor.

Answer: Write the sample statements ( just the statements are required , but you may write the client class too) to construct lamp1 object

3)   Write a class called BankAccount. This class has one instance variable called balance,which is of the data type double. In addition, there are three methods, whose requirements are given below.

  1. Method called getBalance, which is a getter for the instance variable balance.
  2. Method called deposit that has a void return type and takes in a parameter called amount, of the type double. This method calculates a new variable called newBalance = balance + amount, where balance is the current value of instance variable. Once the newBalance is calculated, set the value of instance variable balance = newBalance. Make sure newBalance is declared within the method.
  3. Method called withdraw that has a void return and takes in a parameter called amount, of the type double. This method calculates a new variable called newBalance = balance - amount, where balance, is the current value of instance variable. Once the newBalance is calculated, set the value of instance variable balance = newBalance. Make sure newBalance is declared within the method.
  4. The BankAccount class has a default and a one-arg constructor
  1. Continuing along problem 3), write statements that will create an objects using each of the constructors specified in the BankAccount class. You may call the objects bankAcct1 and bankAcct2. You may choose any appropriate argument values for the overloaded constructors.

 

Answer: Write the sample statements ( just the statements are required , but you may write the client class too) to construct bankAcct1, bankAcct2.

5. Create a class called Employee that represent some basic payroll information about the employee. The instance variables are name , age and salary, which are String, integer and double, respectively .

· The client class using an Employee object should be able to create a new Employee object using the default constructor. Pick any default values of your choice, for the default constructor’s instance variables.

· The client class using an Employee object should be able to create a new Employee object using overloaded constructor that takes in three arguments that provide values for the three instance variables.

· The client class using an Employee object should be able to create a new Employee object using a 2 argument constructor .The two arguments will provide values for name and age instance variables.

 

contact info:

mody_jagal_2007@yahoo.com

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,