Question

The goal of this project is to create a “personal lending library” tool. The user wants...

The goal of this project is to create a “personal lending library” tool. The user wants to keep track of their movies and games – which ones they own, whether or not they are currently loaned out to anyone, and if so, who they were loaned to and on what date. For each item in the library, the program should know its title and format. For a movie, the format is BlueRay or DVD. For a game, the format is the platform the game runs on, such as Windows, Mac, XBox, Playstation, etc. The program should be capable of storing up to 100 items in the library. Right now our library will be wiped when the program terminates, but in the next half of the class we will learn how to make the information stick around between program executions. The program should be capable of the following actions:

 Adding a new item to the library

 Marking an item in the library as on loan

 Listing all of the items in the library (title and format and, if it is currently on loan, the person it is loaned to and the date of the loan)

 Marking an item as returned

Sample Run

: 1. Add new item

2. Mark an item as on loan

3. List all items

4. Mark an item as returned

5. Quit What would you like to do?

1

What is the title?

Star Wars

What is the format?

DVD

You have freedom to design your program however you want, provided that it meets the requirements and follows good design principles. However, if you would like some ideas of where to start, they are provided in this section. This program lends itself well to having two classes, MediaItem and Library, with the fields and methods described below.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

MediaItem.java
===============

public class MediaItem {
private String title;
private String format;
private boolean onLoan;
private String dateLoaned;
private String loanedTo;

public MediaItem(){
title = null;
format = null;
dateLoaned = null;
loanedTo = null;
onLoan = false;
}

public MediaItem(String title, String format){
this.title = title;
this.format = format;
this.onLoan = false;
this.dateLoaned = null;
this.loanedTo = null;

}

public void markOnLoan(String name, String date){
if(onLoan)
System.out.println("The media is already loaned to " + loanedTo + " on " + dateLoaned);
else {
this.loanedTo = name;
this.dateLoaned = date;
this.onLoan = true;

}
}

public void markReturned(){
if(!onLoan)
System.out.println("The media is not yet loaned to anyone");
else {
this.loanedTo = null;
this.dateLoaned = null;
this.onLoan = false;
}
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getFormat() {
return format;
}

public void setFormat(String format) {
this.format = format;
}

public boolean isOnLoan() {
return onLoan;
}

public void setOnLoan(boolean onLoan) {
this.onLoan = onLoan;
}

public String getDateLoaned() {
return dateLoaned;
}

public void setDateLoaned(String dateLoaned) {
this.dateLoaned = dateLoaned;
}

public String getLoanedTo() {
return loanedTo;
}

public void setLoanedTo(String loanedTo) {
this.loanedTo = loanedTo;
}

}

Library.java
===========
import java.util.Scanner;

public class Library {
private MediaItem[] items = new MediaItem[100];
private int numberOfItems;

private static Scanner keyboard = new Scanner(System.in);

public int displayMenu(){
int choice;

System.out.println("1. Add new item");
System.out.println("2. Mark an item as on loan");
System.out.println("3. List all items");
System.out.println("4. Mark an item as returned");
System.out.println("5. Quit");

System.out.print("What would you like to do? ");
choice = keyboard.nextInt();

while(choice < 1 || choice > 5)
{
System.out.print("Invalid choice. Please re-enter option (1-5): ");
choice = keyboard.nextInt();
}
keyboard.nextLine(); //remove newline
return choice;
}

public void addNewItem(String title, String format){
if(numberOfItems < items.length){
items[numberOfItems] = new MediaItem(title, format);
numberOfItems++;
}
else {
System.out.println("No more space to add new item");
}
}


public void markItemOnLoan(String title, String name, String date){
int index = -1;

for(int i = 0; i < numberOfItems; i++){
if(items[i].getTitle().equals(title))
{
index = i;
break;
}
}

if(index == -1)
System.out.println("I'm sorry, I couldn't find " + title + " in the library");
else {
items[index].markOnLoan(name, date);
}

}

public String[] listAllItems(){
String[] str = new String[numberOfItems];

for(int i = 0; i < numberOfItems; i++){
str[i] = items[i].getTitle() + "(" + items[i].getFormat() + ")";

if(items[i].isOnLoan()){
str[i] += " loaned to " + items[i].getLoanedTo() + " on " + items[i].getDateLoaned();
}
}
return str;
}

public void markItemReturned(String title){
int index = -1;

for(int i = 0; i < numberOfItems; i++){
if(items[i].getTitle().equals(title))
{
index = i;
break;
}
}

if(index == -1)
System.out.println("I'm sorry, I couldn't find " + title + " in the library");
else {
items[index].markReturned();
}
}

public static void main(String[] args) {
Library library = new Library();
int choice = 0;
String title, name, date, format;
String[] str;
while(choice != 5){
choice = library.displayMenu();
switch(choice){
case 1:
System.out.print("What is the title? ");
title = keyboard.nextLine();
System.out.print("What is the format? ");
format = keyboard.nextLine();
library.addNewItem(title, format);
break;
case 2:
System.out.print("Which item (enter the title)? ");
title = keyboard.nextLine();
System.out.print("Who are you loaning it to? ");
name = keyboard.nextLine();
System.out.print("When did you loan it to them? ");
date = keyboard.nextLine();
library.markItemOnLoan(title, name, date);
break;

case 3:
str = library.listAllItems();
for(int i = 0; i < str.length; i++)
System.out.println(str[i]);
break;

case 4:
System.out.print("Which item (enter the title)? ");
title = keyboard.nextLine();
library.markItemReturned(title);
break;
case 5:
break;
}

System.out.println();
}

System.out.println("Goodbye!");

}
}

Add a comment
Know the answer?
Add Answer to:
The goal of this project is to create a “personal lending library” tool. The user wants...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will...

    AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will improve our personal lending library tool by (1) adding the ability to delete items from the library, (2) creating a graphical user interface that shows the contents of the library and allows the user to add, delete, check out, or check in an item. (3) using a file to store the library contents so that they persist between program executions, and (4) removing the...

  • Instruction: Create a UML essential use case model for a new library management system. Use a...

    Instruction: Create a UML essential use case model for a new library management system. Use a UML s/w tool to do the work (i.e. MS Visio or LucidChart). A narrative description of the use cases in your model (select one or two for practice) is also required. A narrative template is supplied in this document. To complete the use case narrative, you may make assumptions or create data points as needed. A use case is a depiction of a to...

  • In this assignment you will implement software for your local library. The user of the software...

    In this assignment you will implement software for your local library. The user of the software will be the librarian, who uses your program to issue library cards, check books out to patrons, check books back in, send out overdue notices, and open and close the library. class Calendar We need to deal with the passage of time, so we need to keep track of Java. Declare this variable as private int date within the class itself, not within any...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • Use the case study description and list of requirements below to create an entity-relationship diagram showing...

    Use the case study description and list of requirements below to create an entity-relationship diagram showing the data requirements of the All You Need Are Toys Library database. Your ERD should be able to be implemented in a relational DBMS. Toy libraries operate in a manner similar to book libraries, with members able to borrow a toy for a number of weeks then return it. As with book libraries, toy libraries enable families to have access to a wider range...

  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT