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

Set the employee id to a value less than 1 such as -1. 1 import edu . emory . cs

ID: 3547201 • Letter: S

Question

Set the employee id to a value less than 1 such as -1.

1 import edu . emory . cs170 .hw7 . Employee ;

2

3 public class EmployeeTest {

4

5 public static void main ( String [] args ) {

6

7 Employee e1 = new Employee ();

8

9 e1.id = -1;

10 e1. name = " Mater Towmater ";

11 e1. emailAddress = " mater@cars .com ";

12 e1. title = "Tow Truck Driver ";

13

14 System . out. println (e1. name );

15

16 }

17 }

How can you prevent the attribute from being assigned an invalid value (less than 1)

from within the Employee class? Include the source code below for the modication

you would need to make:

package edu . emory . cs170 .hw7 ;

public class Employee {

}

Explanation / Answer

make the attributes as private { encapsulation. } , write the setters and getters method for attributes ,and in the setters check whether the value of attribute is valid

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote