Question
Can anyone help me with this javascript I can get it to compile but I cant get it to read the text doc. I will
Can anyone help me with this javascript I can get it to compile but I cant get it to read the text doc. I will post the code below please help I have been working on this for about 3 weeks now.
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner;
class Media {
int id; String title; int year, chapter; boolean available;
Media() { }
public Media(int id, String title, int year, int chapter, boolean available) { this.id = id; this.title = title; this.year = year; this.chapter = chapter; this.available = available; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public int getYear() { return year; }
public void setYear(int year) { this.year = year; }
public int getChapter() { return chapter; }
public void setChapter(int chapter) { this.chapter = chapter; }
public boolean isAvailable() { return available; }
public void setAvailable(boolean available) { this.available = available; }
}
import java.util.Scanner;
public class MediaRentalSystem {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (Menu()) { int choice = 0; System.out.println("Enter choice"); choice = sc.nextInt(); Manager m = new Manager(); switch (choice) { case 1: System.out.println("Enter file path load media "); String path = "C:\\Users\\12108\\Desktop\\UMUC CMIS141\\Project 4\\media.txt"; boolean LoadMedia = m.LoadMedia(path); break;
case 2: System.out.println("Enter media title "); String title=sc.next(); m.findMedia(title); break;
case 3: System.out.println("Enter media id :"); int id =sc.nextInt(); m.rentMedia(id); break;
case 9: System.exit(0); break;
default: System.out.println("Enter valid choice "); break; } } sc.close(); }
private static boolean Menu() { System.out.println("Welcome to media rental system"); System.out.println("1: Load Media objects "); System.out.println("2: Find Media objects "); System.out.println("3: Rent Media objects "); System.out.println("9: exit "); return true; } }
class MovieDVD extends Media {
MovieDVD(int id, String title, int year, int chapter, boolean available) { super(id, title, year, chapter, available); }
@Override public String toString() { return "MovieDVD [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year + " available:" + this.available + "] "; }
}
class MusicCD extends Media {
MusicCD(int id, String title, int year, int chapter, boolean available) { super(id, title, year, chapter, available); }
@Override public String toString() { return "MusicCD [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year + " available:" + this.available + "] "; }
}
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner;
class Manager {
static List
Manager() { }
public boolean LoadMedia(String path) { try { File myObj = new File(path); try (Scanner myReader = new Scanner(myObj)) { while (myReader.hasNextLine()) { String data = myReader.nextLine(); String[] str = data.split(" "); switch (str[0]) { case "EBook": boolean add; add = list.add(new EBook(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), Boolean.parseBoolean(str[5]))); break; case "MusicCD": list.add(new MusicCD(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), Boolean.parseBoolean(str[5]))); break; default: list.add(new MovieDVD(Integer.parseInt(str[1]), str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), Boolean.parseBoolean(str[5]))); break; } } System.out.println(list); } return true ; } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); return false; } } public void findMedia(String title) { for(Media m : list) { if(m.getTitle().equals(title)) System.out.print(m.toString()); } } public void rentMedia(int id) { for(Media m : list ) { if(m.getId()==id) { if(m.isAvailable()) System.out.println("media successfully rented out "); else System.out.println("Media with id="+id+" is not available for rent "); } } }
}
class EBook extends Media {
EBook(int id, String title, int year, int chapter, boolean available) { super(id, title, year, chapter, available); }
@Override public String toString() { return "EBook [id:" + this.id + " title:" + this.title + " chapter:" + this.chapter + " year:" + this.year + " available:" + this.available + "] "; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started