Tugas Array dan Inheritance Kelompok 01


Chapter 8

a. Define a class named Employee whose objects are records for employees. Derive this class from the class Person given in Listing 8.1. An employee record inherits an employee’s name from the class Person. In addition, an employee record contains an annual salary represented as a single value of type double, a hire date that gives the year hired as a single value of type int, and an identification number that is a value of type String. Give your class a reasonable complement of constructors, accessor methods, and mutator methods, as well as an equals method. Write a program to fully test your class definition.

b. Buatlah sebuah class dengan nama Employee yang objectnya menyimpan data-data karyawan. Data karyawan terdiri atas nama karyawan. Sebagai tambahan, buatlah data gaji dengan tipe data double, tanggal perekrutan dengan tipe data int, dan nomor pegawai dengan tipe data String.

c.

package tubes.uas.kel.pkg1;

import java.util.Scanner;

public class Employee {

String name [] = new String [5];

String address[] = new String [5];

String position [] = new String [5];

int date[] = new int [5];

String nip []= new String [5];

int salary;

public Employee() {

Scanner x = new Scanner(System.in);

for (int i = 0; i<5; i++) {

System.out.print("Masukkan Nama: ");

name[i] = x.nextLine();

System.out.print("Masukkan NIP: ");

nip [i]= x.nextLine();

System.out.print("Masukkan Tanggal Perekrutan: ");

date[i] = x.nextInt();

x.nextLine();

System.out.print("Masukkan Alamat: ");

address[i] = x.nextLine();

System.out.println("Salary : ");

salary = x.nextInt();

x.nextLine();

switch (salary) {

case 5000000:

System.out.println("You’re Staff");

break;

case 6000000 :

System.out.println("You’re Manager");

break;

case 7000000 :

System.out.println("You’re CEO");

break;

default :

System.out.println("You’re a part-timer");

}

System.out.println();

}

}

public void writeOutput(){

for (int i = 0; i < 5; i++) {

System.out.println("Name : " +name[i]);

System.out.println("NIP : " +nip[i]);

System.out.println("Hired Date : " +date[i]);

System.out.println("Address : " +address[i]);

System.out.println("Salary : " +salary);

System.out.println();

}

}

}

//main class nya:

package tubes.uas.kel.pkg1;

public class TubesUASKel1 {

public static void main(String[] args) {

Employee x = new Employee();

x.writeOutput();

System.out.println("");

}

}

d. output

Anggota Kelompok 1:

Virlyana Efendi (1202164361)

Sevira Hendari Pratiwi (1202160138)

Jannatul Rahmadiani (1202164261)

SI4002


Leave a Reply