Praktikum Ke Tiga PSBO

Di Praktikum ketiga ini dibahas tentang “Association, Composition dan Inheritance” , di sini kami di ajarkan konsep konsep tersebut dengan java sampai detail, dengan diberikan contoh kasus-kasus di alam nyata.
Di praktikum ini kami dianjurkan memakai IDE Netbeans… agar lebih mudah…. lalu koding tentang kasus inheritance di java.
Berikut Sourcecode tugas di praktikum tersebut adalah sbb :

/*
<ul>
  <li>To change this template, choose Tools | Templates</li>
<li>and open the template in the editor.</li>
<li>/</li>
</ul>

package PraktikumPSBO_03_G64062250;

/**
<ul>
  <li>* @author Eko Zulkaryanto</li>
<li>/</li>
</ul>

public class Address {

    private String city;
    private int zip;
    private String street;

    public Address() {
    }

    public Address(String city, int zip, String street) {
        this.city = city;
        this.zip = zip;
        this.street = street;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public int getZip() {
        return zip;
    }

    public void setZip(int zip) {
        this.zip = zip;
    }
}
/*
<ul>
  <li>To change this template, choose Tools | Templates</li>
<li>and open the template in the editor.</li>
<li>/</li>
</ul>

package PraktikumPSBO_03_G64062250;

/**
<ul>
  <li>* @author Eko Zulkaryanto</li>
<li>/</li>
</ul>

public class Course {

    private String instructor;
    private String title;
    private String room;

    public Course() {
    }

    /**
<ul>
  <li>@param instructor adalah variabel nama instruktor mata kuliah</li>
<li>@param title adalah variabel mata kuliah</li>
<li>@param room  adalah variabel nama ruangan mata kuliah</li>
<li>/</li>
</ul>

    public Course(String instructor, String title, String room) {
        this.instructor = instructor;
        this.title = title;
        this.room = room;
    }

    public String getInstructor() {
        return instructor;
    }

    public void setInstructor(String instructor) {
        this.instructor = instructor;
    }

    public String getRoom() {
        return room;
    }

    public void setRoom(String room) {
        this.room = room;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}
/*
<ul>
  <li>To change this template, choose Tools | Templates</li>
<li>and open the template in the editor.</li>
<li>/</li>
</ul>

package PraktikumPSBO_03_G64062250;

/**
<ul>
  <li>* @author Eko Zulkaryanto</li>
<li>/</li>
</ul>

public class Person {

    private String name;
    private Address address;

    //contructor
    public Person() {
    }

    /**
<ul>
  <li>* @param name adalah variabel nama mahasiswa</li>
<li>@param city adalah variabel nama kota tempat tinggal mahasiswa</li>
<li>@param street adalah variabel nama jalan tempat tinggal mahasiswa</li>
<li>@param zip adalah variabel kode post tempat tinggal mahasiswa</li>
<li>/</li>
</ul>

    public Person(String name, String city, int zip, String street) {
        this.name = name;
        this.address = new Address(city, zip, street);
    }

    public String getAddress() {
        return ("City   : " + address.getCity() +
                "\nZip    : " + address.getZip() +
                "\nStreet : " + address.getStreet());
    }

    public void setAddress(String city, int zip, String street) {
        address.setCity(city);
        address.setZip(zip);
        address.setStreet(street);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}//end of class Person
/*
<ul>
  <li>To change this template, choose Tools | Templates</li>
<li>and open the template in the editor.</li>
<li>/</li>
</ul>

package PraktikumPSBO_03_G64062250;

import javax.swing.JOptionPane;

/**
<ul>
  <li>* @author Eko Zulkaryanto</li>
<li>/</li>
</ul>

public class Student extends Person {

    private String school;
    private Course course;

    public Student() {
    }

    public Student(String name, String city, int zip, String street,
            String school, String instructor, String title, String room) {
        super(name, city, zip, street);
        this.school = school;
        this.course = new Course(instructor, title, room);

        System.out.println("Name   : " + super.getName() +
                "\n" + super.getAddress() +
                "\nData Lengkap Masasiswa : \n" + this);

        JOptionPane.showMessageDialog(null, this,
                "Data Lengkap Mahasiswa : ",
                JOptionPane.PLAIN_MESSAGE);
    }

    public void getCourse() {
        System.out.println("Course : " + course.getInstructor() +
                "\nTitle : " + course.getTitle() +
                "\nRoom : " + course.getRoom() +
                "\n");
    }

    public void setCourse(String instructor, String title, String room) {
        course.setInstructor(instructor);
        course.setTitle(title);
        course.setRoom(room);
    }

    public void setPerson(String name, String city, int zip, String street) {
        super.setName(name);
        super.setAddress(city, zip, street);
    }

    public void getPerson() {
        System.out.println("Name    : " + super.getName() +
                " " + super.getAddress());
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    @Override
    public String toString() {
        return "Name   : " + super.getName() +
                "\n" + super.getAddress() +
                "\nSchool     : " + school +
                "\nInstructor : " + course.getInstructor() +
                "\nTitle      : " + course.getTitle() +
                "\nRoom       : " + course.getRoom();
    }
}
/*
<ul>
  <li>To change this template, choose Tools | Templates</li>
<li>and open the template in the editor.</li>
<li>/</li>
</ul>

package PraktikumPSBO_03_G64062250;

import java.awt.HeadlessException;
import javax.swing.JOptionPane;

/**
<ul>
  <li>* @author Eko Zulkaryanto</li>
<li>/</li>
</ul>

public class Main {

    public static void main(String[] args) {

        String name = JOptionPane.showInputDialog(null, "Masukkan nama Mahasiswa : ",
                "Nama Mahasiswa",
                JOptionPane.QUESTION_MESSAGE);
        String city = JOptionPane.showInputDialog(null, "Masukkan nama Kota : ",
                "Alamat Mahasiswa",
                JOptionPane.QUESTION_MESSAGE);
        int zip = 0;
        try {
            zip = Integer.parseInt(JOptionPane.showInputDialog(null, "Masukkan Kode Post : ",
                    "Alamat Mahasiswa",
                    JOptionPane.QUESTION_MESSAGE));
        } catch (HeadlessException headlessException) {
        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(null, "Kode Post harus dalam Integer!");
            try {
                zip = Integer.parseInt(JOptionPane.showInputDialog(null, "Masukkan Kode Post : ",
                        "Alamat Mahasiswa",
                        JOptionPane.QUESTION_MESSAGE));
            } catch (HeadlessException headlessException) {
            } catch (NumberFormatException numberFormatException1) {
            }
        }
        String street = JOptionPane.showInputDialog(null, "Masukkan nama Jalan : ",
                "Alamat Mahasiswa",
                JOptionPane.QUESTION_MESSAGE);
        String school = JOptionPane.showInputDialog(null, "Masukkan nama Universitas : ",
                "Data Kuliah",
                JOptionPane.QUESTION_MESSAGE);
        String instructor = JOptionPane.showInputDialog(null, "Masukkan nama Instructor : ",
                "Data Kuliah",
                JOptionPane.QUESTION_MESSAGE);
        String title = JOptionPane.showInputDialog(null, "Masukkan nama Mata Kuliah : ",
                "Data Kuliah",
                JOptionPane.QUESTION_MESSAGE);
        String room = JOptionPane.showInputDialog(null, "Masukkan nama Ruang Kuliah : ",
                "Data Kuliah",
                JOptionPane.QUESTION_MESSAGE);

        Student student = new Student(name, city, zip, street, school, instructor, title, room);

        System.exit(0);

    }
}

(pas tulisan ini diposting, deadline tugas udah lewat)

About

Seseorang yang terus berusaha menjadi seorang programmer dan blogger sejati di jagad Raya ini.

Tagged with: , ,
Posted in Bahasa Pemrograman, Java Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Community

INDC

MUGI

WSS-ID

SQLServer-Indo

Indonesia Student Portal

Pengunjung
  • 120,657 orang
Yg lg OL di sini
site statistics
%d bloggers like this: