SlideShare a Scribd company logo
1 of 8
Download to read offline
Tested on Eclipse
Both class should be in same package
/***********UNMember class***********/
import java.util.Scanner;
public class UNMember {
/*data member declaration*/
private String name;
private int NUID;
private String netID;
private String collegeLocation;
Scanner input=new Scanner(System.in);
/*Default constructor*/
public UNMember() {
}
/*Parameterized constructor*/
public UNMember(String name, int nUID, String netID) {
setName(name);
setNUID(nUID);
setNetID(netID);
setCollegeLocation();
}
/*Getter and setter method of data member variable*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNUID() {
return NUID;
}
public void setNUID(int nUID) {
NUID = nUID;
}
public String getNetID() {
return netID;
}
public void setNetID(String netID) {
this.netID = netID;
}
public String getCollegeLocation() {
return collegeLocation;
}
public void setCollegeLocation() {
String collegeLocation;
/*Prompt for college location*/
System.out.println("Please Enter the college Location");
collegeLocation=input.nextLine();
this.collegeLocation = collegeLocation;
}
@Override
public String toString() {
return "Name:" + name.toUpperCase() + " NUID=" + NUID + " NetID:" +
netID.toUpperCase() + " Campus Location:" + collegeLocation.toUpperCase()
+ " ";
}
}
/************UNStaff class*************/
import java.text.DecimalFormat;
public class UNStaff extends UNMember{
/*Member data variable declaration*/
private String position;
private double wage;
/*Parameterized constructor*/
public UNStaff(String position, double wage,String name,int NUID,String netID) {
super(name,NUID,netID);
setPosition(position);
setWage(wage);
}
/*Getter and Setter method of data member variable*/
public String getPosition() {
return position;
}
public void setPosition(String position) {
if(position.equals("")|| position==null){
this.position="NOT SET";
}else{
this.position = position;
}
}
public double getWage() {
return wage;
}
/*Set wage , if wage less then 9 then we are setting it to -1*/
public void setWage(double wage) {
if(wage<9){
this.wage=-1;
}else{
this.wage = wage;
}
}
/*ToString method*/
@Override
public String toString() {
String result="Position:" + position.toUpperCase() + " ";
if(this.wage==-1){
result+="Wage:NOT SET";
}else{
result+="Wage:$"+new DecimalFormat("##.00").format(this.wage);
}
return super.toString()+result;
}
public static void main(String args[]){
UNStaff staff=new UNStaff("secretary", 50.6, "David", 123, "UN123");
UNStaff staff1=new UNStaff("cleark", 8, "Sam", 129, "UN129");
System.out.println("**************");
System.out.println(staff.toString());
System.out.println("**************");
System.out.println(staff1.toString());
}
}
/***************output*************/
Please Enter the college Location
california
Please Enter the college Location
Los Angeles
**************
Name:DAVID
NUID=123
NetID:UN123
Campus Location:CALIFORNIA
Position:SECRETARY
Wage:$50.60
**************
Name:SAM
NUID=129
NetID:UN129
Campus Location:LOS ANGELES
Position:CLEARK
Wage:NOT SET
Thanks a lot
Solution
Tested on Eclipse
Both class should be in same package
/***********UNMember class***********/
import java.util.Scanner;
public class UNMember {
/*data member declaration*/
private String name;
private int NUID;
private String netID;
private String collegeLocation;
Scanner input=new Scanner(System.in);
/*Default constructor*/
public UNMember() {
}
/*Parameterized constructor*/
public UNMember(String name, int nUID, String netID) {
setName(name);
setNUID(nUID);
setNetID(netID);
setCollegeLocation();
}
/*Getter and setter method of data member variable*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNUID() {
return NUID;
}
public void setNUID(int nUID) {
NUID = nUID;
}
public String getNetID() {
return netID;
}
public void setNetID(String netID) {
this.netID = netID;
}
public String getCollegeLocation() {
return collegeLocation;
}
public void setCollegeLocation() {
String collegeLocation;
/*Prompt for college location*/
System.out.println("Please Enter the college Location");
collegeLocation=input.nextLine();
this.collegeLocation = collegeLocation;
}
@Override
public String toString() {
return "Name:" + name.toUpperCase() + " NUID=" + NUID + " NetID:" +
netID.toUpperCase() + " Campus Location:" + collegeLocation.toUpperCase()
+ " ";
}
}
/************UNStaff class*************/
import java.text.DecimalFormat;
public class UNStaff extends UNMember{
/*Member data variable declaration*/
private String position;
private double wage;
/*Parameterized constructor*/
public UNStaff(String position, double wage,String name,int NUID,String netID) {
super(name,NUID,netID);
setPosition(position);
setWage(wage);
}
/*Getter and Setter method of data member variable*/
public String getPosition() {
return position;
}
public void setPosition(String position) {
if(position.equals("")|| position==null){
this.position="NOT SET";
}else{
this.position = position;
}
}
public double getWage() {
return wage;
}
/*Set wage , if wage less then 9 then we are setting it to -1*/
public void setWage(double wage) {
if(wage<9){
this.wage=-1;
}else{
this.wage = wage;
}
}
/*ToString method*/
@Override
public String toString() {
String result="Position:" + position.toUpperCase() + " ";
if(this.wage==-1){
result+="Wage:NOT SET";
}else{
result+="Wage:$"+new DecimalFormat("##.00").format(this.wage);
}
return super.toString()+result;
}
public static void main(String args[]){
UNStaff staff=new UNStaff("secretary", 50.6, "David", 123, "UN123");
UNStaff staff1=new UNStaff("cleark", 8, "Sam", 129, "UN129");
System.out.println("**************");
System.out.println(staff.toString());
System.out.println("**************");
System.out.println(staff1.toString());
}
}
/***************output*************/
Please Enter the college Location
california
Please Enter the college Location
Los Angeles
**************
Name:DAVID
NUID=123
NetID:UN123
Campus Location:CALIFORNIA
Position:SECRETARY
Wage:$50.60
**************
Name:SAM
NUID=129
NetID:UN129
Campus Location:LOS ANGELES
Position:CLEARK
Wage:NOT SET
Thanks a lot

More Related Content

Similar to Tested on EclipseBoth class should be in same package.pdf

BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
ankitmobileshop235
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
arrowvisionoptics
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
arjuncp10
 
MenuItemvpublic class MenuItem .pdf
MenuItemvpublic class MenuItem .pdfMenuItemvpublic class MenuItem .pdf
MenuItemvpublic class MenuItem .pdf
aparnaagenciestvm
 
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdfCreate a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
lakshmijewellery
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
aplolomedicalstoremr
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
anokhijew
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
shanki7
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdfTeacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
kareemangels
 

Similar to Tested on EclipseBoth class should be in same package.pdf (20)

BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
Keywords of java
Keywords of javaKeywords of java
Keywords of java
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Create a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdfCreate a class named Student that has the following member variables.pdf
Create a class named Student that has the following member variables.pdf
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
MenuItemvpublic class MenuItem .pdf
MenuItemvpublic class MenuItem .pdfMenuItemvpublic class MenuItem .pdf
MenuItemvpublic class MenuItem .pdf
 
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdfCreate a Code that will add an Add, Edi, and Delete button to the GU.pdf
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Core Java
Core JavaCore Java
Core Java
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Design patterns
Design patternsDesign patterns
Design patterns
 
tested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdftested on eclipseDoublyLinkedList class.pdf
tested on eclipseDoublyLinkedList class.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdfTeacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
Teacher.javaimport java.util.Arrays; import java.util.Scanner;.pdf
 

More from anupamagarud8

Strength The main strength of assessment of epidemiology on human h.pdf
Strength The main strength of assessment of epidemiology on human h.pdfStrength The main strength of assessment of epidemiology on human h.pdf
Strength The main strength of assessment of epidemiology on human h.pdf
anupamagarud8
 
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdf
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdfPsychologist Louis L. Thurstones theory of intellegence can be pre.pdf
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdf
anupamagarud8
 
Please find the answers and explanations belowPart A The qualita.pdf
Please find the answers and explanations belowPart A The qualita.pdfPlease find the answers and explanations belowPart A The qualita.pdf
Please find the answers and explanations belowPart A The qualita.pdf
anupamagarud8
 
Manifest function Manifest functions is defined as the reactions th.pdf
Manifest function Manifest functions is defined as the reactions th.pdfManifest function Manifest functions is defined as the reactions th.pdf
Manifest function Manifest functions is defined as the reactions th.pdf
anupamagarud8
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
anupamagarud8
 
Both structural-functionalist perspective on social inequality and K.pdf
Both structural-functionalist perspective on social inequality and K.pdfBoth structural-functionalist perspective on social inequality and K.pdf
Both structural-functionalist perspective on social inequality and K.pdf
anupamagarud8
 

More from anupamagarud8 (20)

The ligands which show linkage isomers are the onewhich has two dono.pdf
The ligands which show linkage isomers are the onewhich has two dono.pdfThe ligands which show linkage isomers are the onewhich has two dono.pdf
The ligands which show linkage isomers are the onewhich has two dono.pdf
 
Strength The main strength of assessment of epidemiology on human h.pdf
Strength The main strength of assessment of epidemiology on human h.pdfStrength The main strength of assessment of epidemiology on human h.pdf
Strength The main strength of assessment of epidemiology on human h.pdf
 
standard deviationB. it is ameasure of variabilitystandard devia.pdf
standard deviationB. it is ameasure of variabilitystandard devia.pdfstandard deviationB. it is ameasure of variabilitystandard devia.pdf
standard deviationB. it is ameasure of variabilitystandard devia.pdf
 
Solution A virus achieves host specificity through proteins on th.pdf
Solution A virus achieves host specificity through proteins on th.pdfSolution A virus achieves host specificity through proteins on th.pdf
Solution A virus achieves host specificity through proteins on th.pdf
 
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdf
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdfPsychologist Louis L. Thurstones theory of intellegence can be pre.pdf
Psychologist Louis L. Thurstones theory of intellegence can be pre.pdf
 
Please find the answers and explanations belowPart A The qualita.pdf
Please find the answers and explanations belowPart A The qualita.pdfPlease find the answers and explanations belowPart A The qualita.pdf
Please find the answers and explanations belowPart A The qualita.pdf
 
ns1 M.tend to lose electron.lose one electronSolutionn.pdf
ns1 M.tend to lose electron.lose one electronSolutionn.pdfns1 M.tend to lose electron.lose one electronSolutionn.pdf
ns1 M.tend to lose electron.lose one electronSolutionn.pdf
 
Moles = massmolar mass Moles of ( liqiud indium) = 475114.82=4.1.pdf
Moles = massmolar mass Moles of ( liqiud indium) = 475114.82=4.1.pdfMoles = massmolar mass Moles of ( liqiud indium) = 475114.82=4.1.pdf
Moles = massmolar mass Moles of ( liqiud indium) = 475114.82=4.1.pdf
 
Manifest function Manifest functions is defined as the reactions th.pdf
Manifest function Manifest functions is defined as the reactions th.pdfManifest function Manifest functions is defined as the reactions th.pdf
Manifest function Manifest functions is defined as the reactions th.pdf
 
In all SolutionIn all .pdf
In all SolutionIn all .pdfIn all SolutionIn all .pdf
In all SolutionIn all .pdf
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
 
if A U B = implies that A and B both are empty setsboth does.pdf
if A U B = implies that A and B both are empty setsboth does.pdfif A U B = implies that A and B both are empty setsboth does.pdf
if A U B = implies that A and B both are empty setsboth does.pdf
 
hello!Solutionhello!.pdf
hello!Solutionhello!.pdfhello!Solutionhello!.pdf
hello!Solutionhello!.pdf
 
H2A (ACID) Molarity         =    0.15 M Normality N1 =    .pdf
H2A (ACID) Molarity         =    0.15 M Normality N1 =    .pdfH2A (ACID) Molarity         =    0.15 M Normality N1 =    .pdf
H2A (ACID) Molarity         =    0.15 M Normality N1 =    .pdf
 
Financial decision making tools includes Financial Statements, Finan.pdf
Financial decision making tools includes Financial Statements, Finan.pdfFinancial decision making tools includes Financial Statements, Finan.pdf
Financial decision making tools includes Financial Statements, Finan.pdf
 
D. A reply attack occurs when the attacker can intercept session key.pdf
D. A reply attack occurs when the attacker can intercept session key.pdfD. A reply attack occurs when the attacker can intercept session key.pdf
D. A reply attack occurs when the attacker can intercept session key.pdf
 
Both structural-functionalist perspective on social inequality and K.pdf
Both structural-functionalist perspective on social inequality and K.pdfBoth structural-functionalist perspective on social inequality and K.pdf
Both structural-functionalist perspective on social inequality and K.pdf
 
B. SF4Sulfur has an expanded octet in this compound (because it ca.pdf
B. SF4Sulfur has an expanded octet in this compound (because it ca.pdfB. SF4Sulfur has an expanded octet in this compound (because it ca.pdf
B. SF4Sulfur has an expanded octet in this compound (because it ca.pdf
 
B) 0.0968SolutionB) 0.0968.pdf
B) 0.0968SolutionB) 0.0968.pdfB) 0.0968SolutionB) 0.0968.pdf
B) 0.0968SolutionB) 0.0968.pdf
 
Ans. Correct option A. Involves passive water flow down osmotic grad.pdf
Ans. Correct option A. Involves passive water flow down osmotic grad.pdfAns. Correct option A. Involves passive water flow down osmotic grad.pdf
Ans. Correct option A. Involves passive water flow down osmotic grad.pdf
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 

Tested on EclipseBoth class should be in same package.pdf

  • 1. Tested on Eclipse Both class should be in same package /***********UNMember class***********/ import java.util.Scanner; public class UNMember { /*data member declaration*/ private String name; private int NUID; private String netID; private String collegeLocation; Scanner input=new Scanner(System.in); /*Default constructor*/ public UNMember() { } /*Parameterized constructor*/ public UNMember(String name, int nUID, String netID) { setName(name); setNUID(nUID); setNetID(netID); setCollegeLocation(); } /*Getter and setter method of data member variable*/ public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNUID() { return NUID; } public void setNUID(int nUID) { NUID = nUID; }
  • 2. public String getNetID() { return netID; } public void setNetID(String netID) { this.netID = netID; } public String getCollegeLocation() { return collegeLocation; } public void setCollegeLocation() { String collegeLocation; /*Prompt for college location*/ System.out.println("Please Enter the college Location"); collegeLocation=input.nextLine(); this.collegeLocation = collegeLocation; } @Override public String toString() { return "Name:" + name.toUpperCase() + " NUID=" + NUID + " NetID:" + netID.toUpperCase() + " Campus Location:" + collegeLocation.toUpperCase() + " "; } } /************UNStaff class*************/ import java.text.DecimalFormat; public class UNStaff extends UNMember{ /*Member data variable declaration*/ private String position; private double wage; /*Parameterized constructor*/ public UNStaff(String position, double wage,String name,int NUID,String netID) { super(name,NUID,netID); setPosition(position); setWage(wage);
  • 3. } /*Getter and Setter method of data member variable*/ public String getPosition() { return position; } public void setPosition(String position) { if(position.equals("")|| position==null){ this.position="NOT SET"; }else{ this.position = position; } } public double getWage() { return wage; } /*Set wage , if wage less then 9 then we are setting it to -1*/ public void setWage(double wage) { if(wage<9){ this.wage=-1; }else{ this.wage = wage; } } /*ToString method*/ @Override public String toString() { String result="Position:" + position.toUpperCase() + " "; if(this.wage==-1){ result+="Wage:NOT SET"; }else{ result+="Wage:$"+new DecimalFormat("##.00").format(this.wage); } return super.toString()+result; } public static void main(String args[]){
  • 4. UNStaff staff=new UNStaff("secretary", 50.6, "David", 123, "UN123"); UNStaff staff1=new UNStaff("cleark", 8, "Sam", 129, "UN129"); System.out.println("**************"); System.out.println(staff.toString()); System.out.println("**************"); System.out.println(staff1.toString()); } } /***************output*************/ Please Enter the college Location california Please Enter the college Location Los Angeles ************** Name:DAVID NUID=123 NetID:UN123 Campus Location:CALIFORNIA Position:SECRETARY Wage:$50.60 ************** Name:SAM NUID=129 NetID:UN129 Campus Location:LOS ANGELES Position:CLEARK Wage:NOT SET Thanks a lot Solution Tested on Eclipse Both class should be in same package /***********UNMember class***********/ import java.util.Scanner;
  • 5. public class UNMember { /*data member declaration*/ private String name; private int NUID; private String netID; private String collegeLocation; Scanner input=new Scanner(System.in); /*Default constructor*/ public UNMember() { } /*Parameterized constructor*/ public UNMember(String name, int nUID, String netID) { setName(name); setNUID(nUID); setNetID(netID); setCollegeLocation(); } /*Getter and setter method of data member variable*/ public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNUID() { return NUID; } public void setNUID(int nUID) { NUID = nUID; } public String getNetID() { return netID; } public void setNetID(String netID) { this.netID = netID;
  • 6. } public String getCollegeLocation() { return collegeLocation; } public void setCollegeLocation() { String collegeLocation; /*Prompt for college location*/ System.out.println("Please Enter the college Location"); collegeLocation=input.nextLine(); this.collegeLocation = collegeLocation; } @Override public String toString() { return "Name:" + name.toUpperCase() + " NUID=" + NUID + " NetID:" + netID.toUpperCase() + " Campus Location:" + collegeLocation.toUpperCase() + " "; } } /************UNStaff class*************/ import java.text.DecimalFormat; public class UNStaff extends UNMember{ /*Member data variable declaration*/ private String position; private double wage; /*Parameterized constructor*/ public UNStaff(String position, double wage,String name,int NUID,String netID) { super(name,NUID,netID); setPosition(position); setWage(wage); } /*Getter and Setter method of data member variable*/ public String getPosition() { return position; }
  • 7. public void setPosition(String position) { if(position.equals("")|| position==null){ this.position="NOT SET"; }else{ this.position = position; } } public double getWage() { return wage; } /*Set wage , if wage less then 9 then we are setting it to -1*/ public void setWage(double wage) { if(wage<9){ this.wage=-1; }else{ this.wage = wage; } } /*ToString method*/ @Override public String toString() { String result="Position:" + position.toUpperCase() + " "; if(this.wage==-1){ result+="Wage:NOT SET"; }else{ result+="Wage:$"+new DecimalFormat("##.00").format(this.wage); } return super.toString()+result; } public static void main(String args[]){ UNStaff staff=new UNStaff("secretary", 50.6, "David", 123, "UN123"); UNStaff staff1=new UNStaff("cleark", 8, "Sam", 129, "UN129"); System.out.println("**************"); System.out.println(staff.toString()); System.out.println("**************");
  • 8. System.out.println(staff1.toString()); } } /***************output*************/ Please Enter the college Location california Please Enter the college Location Los Angeles ************** Name:DAVID NUID=123 NetID:UN123 Campus Location:CALIFORNIA Position:SECRETARY Wage:$50.60 ************** Name:SAM NUID=129 NetID:UN129 Campus Location:LOS ANGELES Position:CLEARK Wage:NOT SET Thanks a lot