Attachment 1
Attachment 1
1. Write the missing code in the following class definitions. Write a simple client for testing.
//Inheritance: Exercise #1 Class_1 public
class Class_1 {
private int x;
private int y;
public Class_1() {
x = 0;
y = 0;
}
public Class_1(int x1, int y1) {
x = x1;
y = y1;
}
public void print() {
System.out.print(x + " " + y + " ");
}
public String toString() {
return x + " " + y + " ";
}
public void set(int x1, int y1) {
x = x1;
y = y1;
}
}
//Inheritance: Exercise #1 Class_2 public
class Class_2 extends Class_1 {
private int z;
//x = 0, y = 0, z = 0
public Class_2() {
...
}
//x = x1, y = y1, z = z1
public Class_2(int x1, int y1, int z1) {
...
}
//output x, y, z
public void print() {
...
}
public String toString() {
...
}
//x = x1, y = y1, z = z1
public void set(int x1, int y1, int z1) {
...
}
}
2. Create a Person class. The class should contain 2 fields (both Strings called firstName and
lastName) and the following methods:
public void setAll(String first, String last, double rate, double hours,
String dep){
...
}
Write a simple client for testing. Continue the implementation for class ClientEmployee from here:
//Client program for Person/Employee
import java.util.Scanner;
public class ClientEmployee {
public static void main(String[] arg) {
Scanner input = new Scanner(System.in);
String last, first, dept;
double pay_rate;
int hours;
Employee prof = new Employee("John", "Doe", 25.50, 50, "COSC");
//subclass alternate constructor invoked
Employee newEmp = new Employee(); //subclass default constructor
invoked
...
...
}
}
SAMPLE OUTPUT: