Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey, can anyone make this program for me in java? Here is the rubric/instruction

ID: 3731170 • Letter: H

Question

Hey, can anyone make this program for me in java? Here is the rubric/instructions.

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

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? Bioshock Infinite
What is the format? XBox 360

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? 2
Which item (enter the title)? Aliens





I'm sorry, I couldn't find Aliens in the library.

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? 2
Which item (enter the title)? Bioshock Infinite
Who are you loaning it to? Mike
When did you loan it to them? April 2nd

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? 2
Which item (enter the title)? Bioshock Infinite
Who are you loaning it to? James
When did you loan it to them?
April 5th Bioshock Infinite is already on loan to Mike

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? 3
Star Wars (DVD) Bioshock Infinite (XBox 360) loaned to Mike on April 2nd

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? 4
Which item (enter the title)? Star Wars
Star Wars is not currently on loan

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? 4
Which item (enter the title)? Aliens
I'm sorry, I couldn't find Aliens in the library.

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? 4
Which item (enter the title)? Bioshock Infinite

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? 3
Star Wars (DVD) Bioshock Infinite (XBox 360)

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?
5 Goodbye!

Suggestions:

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.

MediaItem

fields:

String title String format boolean onLoan String loanedTo String dateLoaned

methods:

MediaItem() – Constructor to initialize the fields of this media item to default values (null for Strings and false for booleans)

MediaItem(String title, String format) – Constructor to initialize the title and format of this media item. onLoan should be initialized to false. getter and setter methods for all class fields (title, format, onLoan, loanedTo, dateLoaned)

void markOnLoan(String name, String date) – Sets onLoan to true and sets the loanedTo and dateLoaned fields to the parameter values. If onLoan is already true, print an error message saying this item is already loaned out.

void markReturned() – Sets onLoan to false. If onLoan was already false, print an error message saying this item is not currently loaned out.

Library

fields:

MediaItem[] items – An array to hold all of the items in the library. This needs to be big enough to hold 100 items. int numberOfItems – The number of items actually stored in the array. This needs to be incremented whenever a new item is added.

methods:

int displayMenu() – Show the menu of options to the user and read in their choice. Repeat until the user enters a valid option. Then return the option they chose.

void addNewItem(String title, String format) – Create the new MediaItem object, add it to the items array, and increment the numberOfItems variable by one.

void markItemOnLoan(String title, String name, String date) – Iterate through the items array and find the item with the correct title. Call that item's markOnLoan method. If you cannot find the correct item in the array, display an error message.

String[] listAllItems() – Create a String array big enough to hold all of the items in the items array. Iterate through the items array, up to the numberOfItems that array contains. For each item, create a String containing its title and format. If the item is on loan, also include in the string who the item was loaned to and when. Add this string to the String array. When you have converted all of the items to strings, return the String array.

void markItemReturned(String title) – Iterate through the items array and find the item with the correct title. Call that item's markReturned method. If you cannot find the correct item in the array, display an error message.

public static void main(String[] args) – The main method will drive your Library program by repeatedly displaying the menu to the user, prompting the user for any required information, and calling the appropriate method. Similarly, if the method returns information, this data should be displayed from within the main method rather than the Library method. For instance, if the user chooses option 2 (mark an item as on loan), your main method should prompt the user for the title of the item, the name of the person it was loaned to, and the date on which it was loaned, and then call the Library class's markItemOnLoan method with these values. You should not have the markItemOnLoan method get the input from the user directly, because that locks your code into a particular interface (text input).

Hint:

If you have the following problem, where your program does not wait for you to type in the title before asking you for the format, please read this section.

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? What is the format?

The problem here occurs if you are using the same Scanner object throughout your program rather than a new one in each method. There is nothing wrong with this (in fact, it is slightly more efficient), but it can get a little quirky. When you read in a number using a Scanner, as the displayMenu method does, Java reads in the number but not the <ENTER> that the user types after the number. So when you later use the nextLine() method to read in the title, Java sees that <ENTER> still out there from before, and reads it in and assigns it to the title variable. To prevent this, right after you call the Scanner's nextInt() method in your displayMenu method, add this line to skip over the <ENTER> at the end: myScanner.nextLine();

Rubric (Each item is worth three points, for a total of 39)

The program displays the appropriate menu to the user and prompts them for input (checking for invalid input)
The program allows the user to add a new item
The program allows the user to mark an item as on loan to a particular person on a particular date
If the user tries to mark an item on loan that is currently loaned out, an error message is displayed
If the user tries to mark an item on loan that does not exist, an error message is displayed
The program can list the titles and formats of all items in the library

If an item is loaned out, the program includes the person it is loaned to and the date on which it was loaned when listing the item
The program allows the user to mark an item as returned

If the user tries to mark an item that is not currently loaned out as returned, an error message is displayed

If the user tries to mark a non-existent item as returned, an error message is displayed
The program compiles

The program runs

The program follows good coding conventions and design guidelines
Note: If your program does not compile, you will receive a score of 0 on the entire assignment

THANK YOU SO MUCH!

Also, can you show me where each class file ends and begins? I am quite new to java.

Explanation / Answer

Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

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;
> }

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!");

}
}

output
======
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

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? Bioshock Infinite
What is the format? XBox 360

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? 2
Which item (enter the title)? Aliens
Who are you loaning it to? Mike
When did you loan it to them? April 2nd
I'm sorry, I couldn't find Aliens in the library

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? 2
Which item (enter the title)? Bioshock Infinite
Who are you loaning it to? Mike
When did you loan it to them? April 2nd

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? 2
Which item (enter the title)? Bioshock Infinite
Who are you loaning it to? James
When did you loan it to them? April 5th
The media is already loaned to Mike on April 2nd

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? 3
Star Wars(DVD)
Bioshock Infinite(XBox 360) loaned to Mike on April 2nd


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? 4
Which item (enter the title)? Star Wars
The media is not yet loaned to anyone

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? 4
Which item (enter the title)? Aliens
I'm sorry, I couldn't find Aliens in the library

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? 4
Which item (enter the title)? Bioshock Infinite

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? 3
Star Wars(DVD)
Bioshock Infinite(XBox 360)


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? 5