Question: Java assignment - This is the second class code for a personal lending library. I am getting errors on the scanner. Do I need to
Java assignment - This is the second class code for a personal lending library. I am getting errors on the scanner. Do I need to have the import java.util.Scanner with the library class as well as the main code?
Here is the code for the second class.
public class Library {
static Scanner in = new Scanner(System.in); //instantiation
MediaItem t = new MediaItem();
MediaItem[] items = new MediaItem[100];
String[] str = new String[100];
int numberOfItems = 0; //fields
int check = 0;
int called = 0;
int displayMenu(){ //methods
System.out.println("1. Add new item 2. Mark an item as on loan 3. List all items 4. Mark an item as returned 5. Quit");
System.out.print("What would you like to do? ");
int a = in.nextInt();
return a;
}
void addNewItem(String title, String format){
MediaItem item = new MediaItem(title, format);
items[numberOfItems] = item;
numberOfItems++;
}
void markItemOnLoan(String title, String name, String date){
for(int b = 0; b < numberOfItems; b++){
if(title.equals(items[b].title)){
items[b].markOnLoan(name, date);
called = 1;
}
}
if(called == 0)
System.out.println(title + " doesn't exist");
called = 0;
}
void listAllItems(){
for(int c = 0; c < numberOfItems; c++){
if (items[c].onLoan)
str[c] = " " + items[c].title + " " + items[c].format + " loaned to " + items[c].loanedTo + " on " + items[c].dateLoaned;
else
str[c] = " " + items[c].title + " " + items[c].format;
System.out.println(str[c] + " ");
}
}
void markItemReturned(String title){
for(int b = 0; b < numberOfItems; b++){
if(title.equals(items[b].title)){
items[b].markReturned();
check = 1;
}
}
if(check == 0)
System.out.println("Sorry, I couldn't find " + title + " in the library.");
check = 0;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
