Teknik Informatika: Soal UAS Pemrograman Berorientasi Objek (PBO).
in the f ava code belorv,there are some errors relatedto the conceptof PBO[Dealingwith
accessrights, polymorphism, abstract class implementation,and exception handling).
Identify only 5 errors that are containedin the code,explainthe reasonswhy the code
is wrong, and how to solve the problems.
Class Library{
Book collections
= new Book [100] ;
LibraryO
public
co]-lections
{
-
[O]
new Novel
O i
collections
[1]
= new
collections
[2]
= new Book0;
col-lections
[3]
= new
Literature
O ,'
Literature
O ,'
)
inPutBook()
woid
public
{
f o r ( i n t i = 0 ; i < 4 ; i + + )
collections
[i] . inPutfnfo
generateBook
woid
pubJ.ic
O ;
O {
f o r ( i n t i = 0 ; i < 4 ; i + + )
rroid
public
() ;
[i ] . generateBook
collections
O {
PrintRePorts
f o r ( i n t i = 0 ; i < 4 ; i + + )
() ;
Ii ] . PrintRePort
collections
I
Nowel
Class
Book{
extends
langrrage;
String
public
O {
rroid PrintRePort
( " The I S B N
Sys tem. out . Println
( "The Title
System. out. Println
public
System. out. Println
System. out. Println
puJclic
Author
Langlf,age: "*this
void
(cat -=
publ.ic
if
Book{
categ'orY;
String
setCategory(int
cat)
1)
this.categorY
else
if (cat ::
= "Corrq)uter"
2)
title)
( "The
extends
Literature
isbn)
: "*this.
: "*this.
( "The
l
Class
: "*this.
;
{
;
,'
author)
. langrrage)
;
this.
categioryr = '.L;;;u;;E;J
e].se
this.
= \Genetal,.,.
category
)
inqgort
ilawa.util.
. Scanner;
Abstract
Class Book{
protected
String
title,
priwate
String
isbn;
pubJ.ic
abstract
publie
woid
woid
author,-
printReportO
;
inputlnfoo
throws IoExceptior.
| // foException
Scanner input
= ne$, Scanne!(System.in),.
this.title
= input.nextl.ineO
;
this.author
= input.nextl.ineO
need
to
be hand.ts61
;
)
pubJ.ic
woid
this.tit]-e
seti,ttributes(String
= title;
this.author
titJ.e,
String
= author;
author)
t
l
Implementthe designof classDiagrambelowinto
favaprogrammingLanguage.
lbordinabrMab
Kuliah
Ka. Prodi
accessrights, polymorphism, abstract class implementation,and exception handling).
Identify only 5 errors that are containedin the code,explainthe reasonswhy the code
is wrong, and how to solve the problems.
Class Library{
Book collections
= new Book [100] ;
LibraryO
public
co]-lections
{
-
[O]
new Novel
O i
collections
[1]
= new
collections
[2]
= new Book0;
col-lections
[3]
= new
Literature
O ,'
Literature
O ,'
)
inPutBook()
woid
public
{
f o r ( i n t i = 0 ; i < 4 ; i + + )
collections
[i] . inPutfnfo
generateBook
woid
pubJ.ic
O ;
O {
f o r ( i n t i = 0 ; i < 4 ; i + + )
rroid
public
() ;
[i ] . generateBook
collections
O {
PrintRePorts
f o r ( i n t i = 0 ; i < 4 ; i + + )
() ;
Ii ] . PrintRePort
collections
I
Nowel
Class
Book{
extends
langrrage;
String
public
O {
rroid PrintRePort
( " The I S B N
Sys tem. out . Println
( "The Title
System. out. Println
public
System. out. Println
System. out. Println
puJclic
Author
Langlf,age: "*this
void
(cat -=
publ.ic
if
Book{
categ'orY;
String
setCategory(int
cat)
1)
this.categorY
else
if (cat ::
= "Corrq)uter"
2)
title)
( "The
extends
Literature
isbn)
: "*this.
: "*this.
( "The
l
Class
: "*this.
;
{
;
,'
author)
. langrrage)
;
this.
categioryr = '.L;;;u;;E;J
e].se
this.
= \Genetal,.,.
category
)
inqgort
ilawa.util.
. Scanner;
Abstract
Class Book{
protected
String
title,
priwate
String
isbn;
pubJ.ic
abstract
publie
woid
woid
author,-
printReportO
;
inputlnfoo
throws IoExceptior.
| // foException
Scanner input
= ne$, Scanne!(System.in),.
this.title
= input.nextl.ineO
;
this.author
= input.nextl.ineO
need
to
be hand.ts61
;
)
pubJ.ic
woid
this.tit]-e
seti,ttributes(String
= title;
this.author
titJ.e,
String
= author;
author)
t
l
Implementthe designof classDiagrambelowinto
favaprogrammingLanguage.
lbordinabrMab
Kuliah
Ka. Prodi