class called Lamp

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education