UML and Class Description for a Library System: Implementation and Exception Handling, Exercises of Java Programming

A uml class diagram and descriptions for the 'book' and 'library' classes, along with their attributes, methods, and interfaces. The document also includes instructions for implementing the classes, handling exceptions, and creating a test class for the library system. Students of computer science or information technology may find this document useful for understanding object-oriented programming concepts and exception handling.

Typology: Exercises

2020/2021

Uploaded on 04/20/2021

shamma-alshamikh
shamma-alshamikh 🇺🇸

5

(1)

6 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Consider the following UML and class description:
Class Book :
Attributes:
* ISBN: an integer representing the isbn of the book.
* title: a string representing the title of the book.
* type: a character representing the type of the book (‘N’: Novel, ‘E’: Education, ‘C’: Children)
Methods:
* Book (isbn:int, tit:String, t:char): a constructor with parameters.
* tosString(): A method that returns a string representation of the book in the following format:
ISBN_title is a Novel/Education/Children book
InputOutputInterface
<<interface>>
+ load (
filename:String)
+ save
()
Library
-
name: String
-
openYear:int
-
numBooks:int
+ Library (
name:String, oy:int, size:int)
+ add Books (
filename:String)
+ load (
filename:String)
+ save
()
+ sort (
filename:String, type:char)
+
getNumBooks():int
+
getName():String
Book
-
ISBN: int
-
title: String
-
type: char
+ Book (
isbn:int, tit:String, t:char)
+
toString():String
+
getType():char
+
getISBN():int
* books 1
KING SAUD UNIVERSITY!
COLLEGE OF COMPUTER AND INFORMATION SCIENCES
Computer Science Department!
II Programming to Introduction 113: CSC!
Sheet#6
(Files)!
2144-1144 Semester
st
1!
pf2

Partial preview of the text

Download UML and Class Description for a Library System: Implementation and Exception Handling and more Exercises Java Programming in PDF only on Docsity!

Consider the following UML and class description: Class Book :

  • Attributes:
    • ISBN: an integer representing the isbn of the book.
    • title: a string representing the title of the book.
    • type: a character representing the type of the book (‘N’: Novel, ‘E’: Education, ‘C’: Children)
  • Methods:
    • Book (isbn:int, tit:String, t:char): a constructor with parameters.
    • tosString(): A method that returns a string representation of the book in the following format: ISBN _ title is a Novel/Education/Children book InputOutputInterface <>
  • load (filename:String)
  • save () Library
  • name: String
  • openYear:int
  • numBooks:int
  • Library (name:String, oy:int, size:int)
  • add Books (filename:String)
  • load (filename:String)
  • save ()
  • sort (filename:String, type:char) +getNumBooks():int +getName():String Book
  • ISBN: int
  • title: String
  • type: char
  • Book (isbn:int, tit:String, t:char) +toString():String
  • getType():char +getISBN():int
  • books 1

KING SAUD UNIVERSITY

COLLEGE OF COMPUTER AND INFORMATION SCIENCES

Computer Science Department CSC 113:IntroductiontoProgramming II Sheet# 6 (Files) 1 stSemester 1441 - 1442

Class Library :

  • Attributes:
    • name: a string holding the name of the library.
    • openYear: an integer representing the year the library was open.
    • numBooks: an integer maintaining the number of books currently in the library.
  • Methods:
    • Library (name:String, oy:int, size:int): a constructor with parameters.
    • add Books (filename:String): This method receives a name of a text file and containing book information. The method should read the information of each book and adds it to the array of books. Assume that the text file is formatted so each line contains one book info in the order : ISBN title type. Note that the number of books may vary in the file.
    • load (filename:String): This method receives a binary file consisting of an integer representing the open year, followed by another integer counting the number of books, followed by an array containing book objects. The method reads this info and saves it in the current object state. The library’s name should be assigned the name of the file (without the extension) Note : The file contains a mixture of data types
    • save (): This method creates a binary file having the name of the library and a .dat extension and saves the current object state in it as follows: the library opening year, followed by the current number of books, followed by the array of books all at once. Note : The file contains a mixture of data types
    • sort (filename:String, type:char): This method receives a name of an object file and saves in it all the books matching the received type.

Question :

  1. Implement the interface InputOutputInterface, class library, and class Book.
  2. Methods addBooks and sort in class library should handle the exceptions that might occur in them by printing an appropriate message.
  3. Methods load and save in class library should propagate the exceptions that might occur in them to the main method.
  4. Create a test class named TestLibrary containing a main method that performs the following : a. Create a library object name KSL having the name King Salman Library that was opened year 1374 and that can hold a maximum of 200 books. b. Read the information of the books in the file “Books.txt” and add them to KSL. c. Save the current state of KSL to a file “King Salman Library.dat”. d. Save all the education books in KSL in a file named “educationBooks.dat”.
  5. The main method should handle all exception by printing an appropriate message.