You are on page 1of 4

Nama : Juliansyah Darmawan

NPM : 14402426
Kelas : MIF K-42/14
1. Class Diagram

Catatan : Tambahan Set untuk mengisikan nilai atribute di kelas tersebut.


Get untuk mengambil isi atribute di kelas tersebut.
Disoal ada kesalahan coding yaitu saat hardwarebook h = new
hardwarebook()
Error karena tidak ada class hardwarebook
2. book.java
public class book{
int price, pages;
public book(){
this.price = 0;
this.pages = 0;
}
public book(int price, int pages){
this.price = price;
this.pages = pages;
}
public int getPrice(){
return this.price;
}
public int getPages(){
return this.pages;
}
public void setPrice(int price){
this.price = price;
}
public void setPages(int pages){
this.pages = pages;
}
public void show(){
System.out.println("Price of book is "+getPrice());
System.out.println("Pages of book is "+getPages());
}
}

softwarebook.java
public class softwarebook extends book{
String softwareName, softwareVersion;
public softwarebook (){
super();
this.softwareName = "Software Has Not been set";
this.softwareVersion = "Software Version Has Not been set";
}
public softwarebook(String softwareName, String softwareVersion, int
price, int pages){
super(price, pages);
this.softwareName = softwareName;
this.softwareVersion = softwareVersion;
}

public String getSoftwareName(){


return this.softwareName;
}
public String getSoftwareVersion(){
return this.softwareVersion;
}
public void setSoftwareName(String softwareName){
this.softwareName = softwareName;
}
public void setSoftwareVersion(String softwareVersion){
this.softwareVersion = softwareVersion;
}
public void showDetail(){
show();
System.out.println("Software Name is "+getSoftwareName());
System.out.println("Software Version is "+getSoftwareVersion());
}
}

CPlus.java
public class CPlus extends softwarebook{
String author, title;
public CPlus (){
super();
this.softwareName = "Author Has Not been set";
this.softwareVersion = "Title Has Not been set";
}
public CPlus(String author, String title, String softwareName, String
softwareVersion, int price, int pages){
super(softwareName, softwareVersion, price, pages);
this.author = author;
this.title = title;
}

public String getAuthor(){


return this.author;
}
public String getTitle(){
return this.title;
}
public void setAuthor(String author){
this.author = author;
}
public void setTitle(String title){
this.title = title;
}
public void showData(){
showDetail();
System.out.println("Author is "+getAuthor());
System.out.println("TItle is "+getTitle());
}
}

BookApp. .java
public class BookApp{
public static void main(String args[]){
CPlus c1 = new CPlus();
CPlus c2 = new CPlus("Juliansyah","OOP BOOK", "ZRZ Application", "V-
01", 150000, 150);
c2.showData();

c1.setAuthor("Darmawan");
c1.setTitle("Easy way to learn java");
c1.setSoftwareName("ZRZ Software Book");
c1.setSoftwareVersion("V-02");
c1.setPrice(200000);
c1.setPages(50);
c1.showData();
}
}

You might also like