SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
Use the Java hierarchy you posted in week 5 (corrected based on any feedback you may have
received). Add a user-defined exception that can be thrown by one of the methods as part of the
validation or error checking. The main method should then create an instance of the class and
call the method in such a way that the exception is thrown (e.g. invalid input or state of the
system). Submit your program as an attached .java file and post a screenshot to show that you
have been able to successfully run that program. Make sure your submission adheres to the
Submission Requirements document.
public class Employee {
String empName;
double salary;
//constructor of Employee
Employee(String empName, double salary) {
this.empName = empName;
this.salary = salary;
}
//function to return the employee name
String getName() {
return empName;
}
//function to return the salary
double getSalary() {
return salary;
}
public String toString() {
String output = "";
output = output + "Name: " + getName() + "n";
output = output + "Salary: $" + getSalary() + "n";
return output;
}
}
class Faculty extends Employee {
String deptName;
//constructor of the Faculty
Faculty(String nm, double sal, String dnm) {
//passing the name and salary to superclass constructor
super(nm, sal);
deptName = dnm;
}
//function to return department name
String getDeptName() {
return deptName;
}
//override toString method to include department name
@Override
public String toString() {
return super.toString() + "Department Name: " + getDeptName() + "n";
}
}
class Staff extends Employee {
String jobTitle;
//constructor of Staff class
Staff(String nm, double sal, String title) {
//passing the name and salary to superclass constructor
super(nm, sal);
jobTitle = title;
}
//function to return job title
String getJobTitle() {
return jobTitle;
}
//overload the toString method to include a boolean parameter
public String toString(boolean includeSalary) {
if (includeSalary) {
return super.toString() + "Job Title: " + getJobTitle() + "n";
} else {
return "Job Title: " + getJobTitle() + "n";
}
}
}
public class Main {
public static void main(String[] args) {
Faculty faculty = new Faculty("John ", 60000, "Mathematics");
System.out.println(faculty.toString());
Staff staff = new Staff("Smith", 40000, "Administrative Assistant");
System.out.println(staff.toString());
System.out.println(staff.toString(false));
}
}

Weitere ähnliche Inhalte

Ähnlich wie Use the Java hierarchy you posted in week 5 (corrected based on any fe.pdf

Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfirshadkumar3
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdfanithareadymade
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptRithwikRanjan
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
11slide
11slide11slide
11slideIIUM
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfadithyaups
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfarishmarketing21
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritanceshatha00
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxinfantsuk
 
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAXМихаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAXDrupalSib
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdffeelingspaldi
 

Ähnlich wie Use the Java hierarchy you posted in week 5 (corrected based on any fe.pdf (20)

Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Unit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docxUnit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docx
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
11slide.ppt
11slide.ppt11slide.ppt
11slide.ppt
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
11slide
11slide11slide
11slide
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
 
Test program
Test programTest program
Test program
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAXМихаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 

Mehr von anagpalknitwears

Use the Report Wizard to create a report based on the primary Hiker ta.pdf
Use the Report Wizard to create a report based on the primary Hiker ta.pdfUse the Report Wizard to create a report based on the primary Hiker ta.pdf
Use the Report Wizard to create a report based on the primary Hiker ta.pdfanagpalknitwears
 
Use the information below to answer the following question(s)- Ontario.pdf
Use the information below to answer the following question(s)- Ontario.pdfUse the information below to answer the following question(s)- Ontario.pdf
Use the information below to answer the following question(s)- Ontario.pdfanagpalknitwears
 
Use the information below to answer the questions- Number of units -1-.pdf
Use the information below to answer the questions- Number of units -1-.pdfUse the information below to answer the questions- Number of units -1-.pdf
Use the information below to answer the questions- Number of units -1-.pdfanagpalknitwears
 
Use the income statement to compute a Compute vertical common-size ana.pdf
Use the income statement to compute a Compute vertical common-size ana.pdfUse the income statement to compute a Compute vertical common-size ana.pdf
Use the income statement to compute a Compute vertical common-size ana.pdfanagpalknitwears
 
Use the image below to identify the lettered elements of atmospheric c.pdf
Use the image below to identify the lettered elements of atmospheric c.pdfUse the image below to identify the lettered elements of atmospheric c.pdf
Use the image below to identify the lettered elements of atmospheric c.pdfanagpalknitwears
 
Use the image to answer the following questions 1- Does glucose transp.pdf
Use the image to answer the following questions 1- Does glucose transp.pdfUse the image to answer the following questions 1- Does glucose transp.pdf
Use the image to answer the following questions 1- Does glucose transp.pdfanagpalknitwears
 
Using SPIM- write and test a program that reads in three integers and.pdf
Using SPIM- write and test a program that reads in three integers and.pdfUsing SPIM- write and test a program that reads in three integers and.pdf
Using SPIM- write and test a program that reads in three integers and.pdfanagpalknitwears
 
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdf
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdfUsing simpele Inoec tepiessian and given that the prico pec cup is $2-.pdf
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdfanagpalknitwears
 
Using PowerPoint create a slideshow of your brain dissection along sid.pdf
Using PowerPoint create a slideshow of your brain dissection along sid.pdfUsing PowerPoint create a slideshow of your brain dissection along sid.pdf
Using PowerPoint create a slideshow of your brain dissection along sid.pdfanagpalknitwears
 
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdf
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdfUsing Probability in Genetics 1- Let's say you roll a dice (standard s.pdf
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdfanagpalknitwears
 
Using Pep8- 24- Write an assembly language program that corresponds ex.pdf
Using Pep8- 24- Write an assembly language program that corresponds ex.pdfUsing Pep8- 24- Write an assembly language program that corresponds ex.pdf
Using Pep8- 24- Write an assembly language program that corresponds ex.pdfanagpalknitwears
 
Using JK flip-flops- design one typical stage of an A register (Accumu.pdf
Using JK flip-flops- design one typical stage of an A register (Accumu.pdfUsing JK flip-flops- design one typical stage of an A register (Accumu.pdf
Using JK flip-flops- design one typical stage of an A register (Accumu.pdfanagpalknitwears
 
Using figure A- list the sequence of events represented by the letters.pdf
Using figure A- list the sequence of events represented by the letters.pdfUsing figure A- list the sequence of events represented by the letters.pdf
Using figure A- list the sequence of events represented by the letters.pdfanagpalknitwears
 
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdf
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdfUsing GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdf
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdfanagpalknitwears
 
Using experimental design as in analysis of variance (ANOVA)- Determin.pdf
Using experimental design as in analysis of variance (ANOVA)- Determin.pdfUsing experimental design as in analysis of variance (ANOVA)- Determin.pdf
Using experimental design as in analysis of variance (ANOVA)- Determin.pdfanagpalknitwears
 
Using examples and illustrations- discuss various ways in which inform.pdf
Using examples and illustrations- discuss various ways in which inform.pdfUsing examples and illustrations- discuss various ways in which inform.pdf
Using examples and illustrations- discuss various ways in which inform.pdfanagpalknitwears
 
Using examples- discuss the pros and cons of copyright protections fro.pdf
Using examples- discuss the pros and cons of copyright protections fro.pdfUsing examples- discuss the pros and cons of copyright protections fro.pdf
Using examples- discuss the pros and cons of copyright protections fro.pdfanagpalknitwears
 
Using each of the combining forms below to create medical terms- Spell.pdf
Using each of the combining forms below to create medical terms- Spell.pdfUsing each of the combining forms below to create medical terms- Spell.pdf
Using each of the combining forms below to create medical terms- Spell.pdfanagpalknitwears
 
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdf
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdfUsing C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdf
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdfanagpalknitwears
 
Using C++- Keep it simple please Part 1- Prompt the user to enter 3 s.pdf
Using C++- Keep it simple please  Part 1- Prompt the user to enter 3 s.pdfUsing C++- Keep it simple please  Part 1- Prompt the user to enter 3 s.pdf
Using C++- Keep it simple please Part 1- Prompt the user to enter 3 s.pdfanagpalknitwears
 

Mehr von anagpalknitwears (20)

Use the Report Wizard to create a report based on the primary Hiker ta.pdf
Use the Report Wizard to create a report based on the primary Hiker ta.pdfUse the Report Wizard to create a report based on the primary Hiker ta.pdf
Use the Report Wizard to create a report based on the primary Hiker ta.pdf
 
Use the information below to answer the following question(s)- Ontario.pdf
Use the information below to answer the following question(s)- Ontario.pdfUse the information below to answer the following question(s)- Ontario.pdf
Use the information below to answer the following question(s)- Ontario.pdf
 
Use the information below to answer the questions- Number of units -1-.pdf
Use the information below to answer the questions- Number of units -1-.pdfUse the information below to answer the questions- Number of units -1-.pdf
Use the information below to answer the questions- Number of units -1-.pdf
 
Use the income statement to compute a Compute vertical common-size ana.pdf
Use the income statement to compute a Compute vertical common-size ana.pdfUse the income statement to compute a Compute vertical common-size ana.pdf
Use the income statement to compute a Compute vertical common-size ana.pdf
 
Use the image below to identify the lettered elements of atmospheric c.pdf
Use the image below to identify the lettered elements of atmospheric c.pdfUse the image below to identify the lettered elements of atmospheric c.pdf
Use the image below to identify the lettered elements of atmospheric c.pdf
 
Use the image to answer the following questions 1- Does glucose transp.pdf
Use the image to answer the following questions 1- Does glucose transp.pdfUse the image to answer the following questions 1- Does glucose transp.pdf
Use the image to answer the following questions 1- Does glucose transp.pdf
 
Using SPIM- write and test a program that reads in three integers and.pdf
Using SPIM- write and test a program that reads in three integers and.pdfUsing SPIM- write and test a program that reads in three integers and.pdf
Using SPIM- write and test a program that reads in three integers and.pdf
 
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdf
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdfUsing simpele Inoec tepiessian and given that the prico pec cup is $2-.pdf
Using simpele Inoec tepiessian and given that the prico pec cup is $2-.pdf
 
Using PowerPoint create a slideshow of your brain dissection along sid.pdf
Using PowerPoint create a slideshow of your brain dissection along sid.pdfUsing PowerPoint create a slideshow of your brain dissection along sid.pdf
Using PowerPoint create a slideshow of your brain dissection along sid.pdf
 
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdf
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdfUsing Probability in Genetics 1- Let's say you roll a dice (standard s.pdf
Using Probability in Genetics 1- Let's say you roll a dice (standard s.pdf
 
Using Pep8- 24- Write an assembly language program that corresponds ex.pdf
Using Pep8- 24- Write an assembly language program that corresponds ex.pdfUsing Pep8- 24- Write an assembly language program that corresponds ex.pdf
Using Pep8- 24- Write an assembly language program that corresponds ex.pdf
 
Using JK flip-flops- design one typical stage of an A register (Accumu.pdf
Using JK flip-flops- design one typical stage of an A register (Accumu.pdfUsing JK flip-flops- design one typical stage of an A register (Accumu.pdf
Using JK flip-flops- design one typical stage of an A register (Accumu.pdf
 
Using figure A- list the sequence of events represented by the letters.pdf
Using figure A- list the sequence of events represented by the letters.pdfUsing figure A- list the sequence of events represented by the letters.pdf
Using figure A- list the sequence of events represented by the letters.pdf
 
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdf
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdfUsing GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdf
Using GDP per capita in 2020 (measured in U-S- dollars- corrected for.pdf
 
Using experimental design as in analysis of variance (ANOVA)- Determin.pdf
Using experimental design as in analysis of variance (ANOVA)- Determin.pdfUsing experimental design as in analysis of variance (ANOVA)- Determin.pdf
Using experimental design as in analysis of variance (ANOVA)- Determin.pdf
 
Using examples and illustrations- discuss various ways in which inform.pdf
Using examples and illustrations- discuss various ways in which inform.pdfUsing examples and illustrations- discuss various ways in which inform.pdf
Using examples and illustrations- discuss various ways in which inform.pdf
 
Using examples- discuss the pros and cons of copyright protections fro.pdf
Using examples- discuss the pros and cons of copyright protections fro.pdfUsing examples- discuss the pros and cons of copyright protections fro.pdf
Using examples- discuss the pros and cons of copyright protections fro.pdf
 
Using each of the combining forms below to create medical terms- Spell.pdf
Using each of the combining forms below to create medical terms- Spell.pdfUsing each of the combining forms below to create medical terms- Spell.pdf
Using each of the combining forms below to create medical terms- Spell.pdf
 
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdf
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdfUsing C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdf
Using C++- Keep it simple please- What is Call-By-Value and Call-By-Re.pdf
 
Using C++- Keep it simple please Part 1- Prompt the user to enter 3 s.pdf
Using C++- Keep it simple please  Part 1- Prompt the user to enter 3 s.pdfUsing C++- Keep it simple please  Part 1- Prompt the user to enter 3 s.pdf
Using C++- Keep it simple please Part 1- Prompt the user to enter 3 s.pdf
 

Kürzlich hochgeladen

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
The role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipThe role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipKarl Donert
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsArubSultan
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPCeline George
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxMadhavi Dharankar
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...HetalPathak10
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 

Kürzlich hochgeladen (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
The role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipThe role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenship
 
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
Mattingly "AI & Prompt Design" - Introduction to Machine Learning"
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristics
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERP
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptx
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 

Use the Java hierarchy you posted in week 5 (corrected based on any fe.pdf

  • 1. Use the Java hierarchy you posted in week 5 (corrected based on any feedback you may have received). Add a user-defined exception that can be thrown by one of the methods as part of the validation or error checking. The main method should then create an instance of the class and call the method in such a way that the exception is thrown (e.g. invalid input or state of the system). Submit your program as an attached .java file and post a screenshot to show that you have been able to successfully run that program. Make sure your submission adheres to the Submission Requirements document. public class Employee { String empName; double salary; //constructor of Employee Employee(String empName, double salary) { this.empName = empName; this.salary = salary; } //function to return the employee name String getName() { return empName; } //function to return the salary double getSalary() { return salary; } public String toString() { String output = ""; output = output + "Name: " + getName() + "n";
  • 2. output = output + "Salary: $" + getSalary() + "n"; return output; } } class Faculty extends Employee { String deptName; //constructor of the Faculty Faculty(String nm, double sal, String dnm) { //passing the name and salary to superclass constructor super(nm, sal); deptName = dnm; } //function to return department name String getDeptName() { return deptName; } //override toString method to include department name @Override public String toString() { return super.toString() + "Department Name: " + getDeptName() + "n"; } } class Staff extends Employee {
  • 3. String jobTitle; //constructor of Staff class Staff(String nm, double sal, String title) { //passing the name and salary to superclass constructor super(nm, sal); jobTitle = title; } //function to return job title String getJobTitle() { return jobTitle; } //overload the toString method to include a boolean parameter public String toString(boolean includeSalary) { if (includeSalary) { return super.toString() + "Job Title: " + getJobTitle() + "n"; } else { return "Job Title: " + getJobTitle() + "n"; } } } public class Main { public static void main(String[] args) { Faculty faculty = new Faculty("John ", 60000, "Mathematics");
  • 4. System.out.println(faculty.toString()); Staff staff = new Staff("Smith", 40000, "Administrative Assistant"); System.out.println(staff.toString()); System.out.println(staff.toString(false)); } }