Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Write a class encapsulating the concept of a course- assuming a course.docx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Assignment 7
Assignment 7
Wird geladen in …3
×

Hier ansehen

1 von 1 Anzeige

Write a class encapsulating the concept of a course- assuming a course.docx

Herunterladen, um offline zu lesen

Write a class encapsulating the concept of a course, assuming a course has the following attributes: a code (ie: 1324), a description (\" Java\") and a number of credits (4). Include a constructor, the sets and gets, and methods toString and equals. Write a client class to test all the methods in your class.
Solution
public class EncapsulationDemo{ private int ssn; private String empName; private int empAge; //Getter and Setter methods public int getEmpSSN(){ return ssn; } public String getEmpName(){ return empName; } public int getEmpAge(){ return empAge; } public void setEmpAge(int newValue){ empAge = newValue; } public void setEmpName(String newValue){ empName = newValue; } public void setEmpSSN(int newValue){ ssn = newValue; } } public class EncapsTest{ public static void main(String args[]){ EncapsulationDemo obj = new EncapsulationDemo(); obj.setEmpName(\"Mario\"); obj.setEmpAge(32); obj.setEmpSSN(112233); System.out.println(\"Employee Name: \" + obj.getEmpName()); System.out.println(\"Employee SSN: \" + obj.getEmpSSN()); System.out.println(\"Employee Age: \" + obj.getEmpAge()); } }
.

Write a class encapsulating the concept of a course, assuming a course has the following attributes: a code (ie: 1324), a description (\" Java\") and a number of credits (4). Include a constructor, the sets and gets, and methods toString and equals. Write a client class to test all the methods in your class.
Solution
public class EncapsulationDemo{ private int ssn; private String empName; private int empAge; //Getter and Setter methods public int getEmpSSN(){ return ssn; } public String getEmpName(){ return empName; } public int getEmpAge(){ return empAge; } public void setEmpAge(int newValue){ empAge = newValue; } public void setEmpName(String newValue){ empName = newValue; } public void setEmpSSN(int newValue){ ssn = newValue; } } public class EncapsTest{ public static void main(String args[]){ EncapsulationDemo obj = new EncapsulationDemo(); obj.setEmpName(\"Mario\"); obj.setEmpAge(32); obj.setEmpSSN(112233); System.out.println(\"Employee Name: \" + obj.getEmpName()); System.out.println(\"Employee SSN: \" + obj.getEmpSSN()); System.out.println(\"Employee Age: \" + obj.getEmpAge()); } }
.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Write a class encapsulating the concept of a course- assuming a course.docx (20)

Weitere von lez31palka (20)

Anzeige

Aktuellste (20)

Write a class encapsulating the concept of a course- assuming a course.docx

  1. 1. Write a class encapsulating the concept of a course, assuming a course has the following attributes: a code (ie: 1324), a description (" Java") and a number of credits (4). Include a constructor, the sets and gets, and methods toString and equals. Write a client class to test all the methods in your class. Solution public class EncapsulationDemo{ private int ssn; private String empName; private int empAge; //Getter and Setter methods public int getEmpSSN(){ return ssn; } public String getEmpName(){ return empName; } public int getEmpAge(){ return empAge; } public void setEmpAge(int newValue){ empAge = newValue; } public void setEmpName(String newValue){ empName = newValue; } public void setEmpSSN(int newValue){ ssn = newValue; } } public class EncapsTest{ public static void main(String args[]){ EncapsulationDemo obj = new EncapsulationDemo(); obj.setEmpName("Mario"); obj.setEmpAge(32); obj.setEmpSSN(112233); System.out.println("Employee Name: " + obj.getEmpName()); System.out.println("Employee SSN: " + obj.getEmpSSN()); System.out.println("Employee Age: " + obj.getEmpAge()); } }

×