TUGAS PBO A - INHERITANCE

TUGAS PBO A - INHERITANCE




Tugas PBO Kali ini membua inheritence dari sebuah sistem yang menyimpan list Item, CD dan DVD

Nama : Naulia Adam Kuncoro
NRP   : 05111740000155
Kelas : PBO A

Membuat database untuk menyimpan data CD, DVD, Item

Terdapat 4 class yang ada:
1. Item
Source Code
 /**  
{
    private String title;
    private int playingTime;
    private boolean gotIt;
    private String comment;

    public Item(String theTitle,int time)
    {
        // initialise instance variables
        title = theTitle;
        playingTime = time;
        gotIt = false;
        comment = "";
    }
    public void setComment(String comment)
    {
        this.comment=comment;
    }
    public String getComment()
    {
        return comment;
    }
    public void setOwn(boolean ownIt)
    {
        gotIt=ownIt;
    }
    public boolean getOwn()
    {
        return gotIt;
    }
    public void print()
    {
        System.out.print("title:"+ title +"(" + playingTime + "mins)");
        if(gotIt){
            System.out.println("*");
        }else{
            System.out.println();
        }
        System.out.println(" "+ comment);
    }
}
hasil run:





2. CD
Source Code
 /**  
public class CD extends Item
{
    private String artist;
    private int numberOfTracks;

    public CD(String theTitle, String theArtist, int tracks, int time)
    {
        super(theTitle,time);
        artist = theArtist;
        numberOfTracks = tracks;
    }
    public String getArtist(){
        return artist;
    }
    public int getNumberOfTracks()
    {
        return numberOfTracks;
    }
}
hasil run :




3. DVD
Source Code
 /**  
public class DVD extends Item
{
    private String director;

    public DVD(String theTitle,String theDirector, int time)
    {
        super(theTitle,time);
        director = theDirector;
    }
    public String getDirector()
    {
        return director;
    }
}

4. DATABASE
Source Code
 /**  
import java.util.ArrayList;
public class Database
{
    private ArrayListitems;

    public Database()
    {
        items = new ArrayList();
    }
    public void addItem(Item theItem){
        items.add(theItem);
    }
    public void list(){
        for(Item item : items){
            item.print();
            System.out.println();
        }
    }
}

Komentar

Postingan populer dari blog ini

UTS PBKK (26 Maret 2020)

EAS PBKK Contribution Based Evaluation