Question: all the classes are provided, the TesterClass has an error can someone please fix it? http://www.chegg.com/homework-help/questions-and-answers/programming-language-java-post-complete-code-please-classes-serializable-comparable-driver-q22870063 import java.util.ArrayList; public class Administrator { ArrayList administrators; Administrator()
all the classes are provided, the TesterClass has an error can someone please fix it?
http://www.chegg.com/homework-help/questions-and-answers/programming-language-java-post-complete-code-please-classes-serializable-comparable-driver-q22870063
import java.util.ArrayList;
public class Administrator { ArrayList
import java.io.Serializable; import java.util.ArrayList;
public class Library implements Serializable { //arraylist of items variable private ArrayList
//searches for input title and if it matches then it returns an arraylist //with the same words as the input public ArrayList
public ArrayList
}
public class Person { private String name; private String lastName; private String id; private String email; private String phone; private boolean goodStanding; public Person() { //nothing } public Person(String n, String l, String id, String email, String phone) { this.name = n; this.lastName = l; setId(id); setEmail(email); setPhone(phone); goodStanding = true; } //prints the toString of the class person public String toString() { String toReturn; toReturn = this.name + " " + this.lastName; toReturn += " " + id + " " + this.email; toReturn += " " + this.phone; return toReturn; } //validates the i.d. of the person private boolean validateId(String id) { if(id.length() != 10) return false; for(int i = 0; i < id.length(); i++) { if(Character.isAlphabetic(id.charAt(i))) return false; } return true; } //validates the email of the person private boolean validateEmail(String email) { boolean atMarker = false; for(int i = 0; i < email.length(); i++) { if(email.charAt(i) == '@') atMarker = true; } if(!atMarker) return false; else return true; } //validates the phone number private boolean validatePhone(String phone) { if(phone.length() != 10) return false; for(int i = 0; i < phone.length(); i++) { if(!Character.isDigit(phone.charAt(i))) return false; } return true; } //compares to another person by last name public boolean compareTo(Person other) { if(!other.lastName.equalsIgnoreCase(this.lastName)) return false; else return true; } boolean equals(Person other) { if(this.id.equalsIgnoreCase(other.id)) return false; else return true; } //----------------------Setters and Getters---------------------- public String getName() { return name; } public void setName(String name) { this.name = name; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getId() { return id; } private void setId(String id) { if(validateId(id)) this.id = id; else throw new IllegalArgumentException(); } public String getEmail() { return email; } private void setEmail(String email) { if(validateEmail(email)) this.email = email; else throw new IllegalArgumentException(); } public String getPhone() { return phone; } private void setPhone(String phone) { if(validatePhone(phone)) this.phone = phone; else throw new IllegalArgumentException(); }
public boolean isGoodStanding() { return goodStanding; }
public void setGoodStanding(boolean goodStanding) { this.goodStanding = goodStanding; } }
import java.util.StringTokenizer; import java.io.Serializable;
public class Item implements Serializable { String title; String subject; String author; String publisher; String yearPublished;//validated? boolean status; String type; // can only be book, journal, audio cd, or video cd public Item(String t, String s, String a, String p, String y, boolean stat, String type) { title = t; subject = s; author = a; publisher = p; setYearPublished(y); status = stat; setType(type); } public Item() { title = ""; subject = ""; author = ""; publisher = ""; yearPublished = ""; status = false; type = ""; } public boolean contains(String word) { StringTokenizer token = new StringTokenizer(this.title); while(token.hasMoreTokens()) if(token.nextToken().equalsIgnoreCase(word)) return true; return false; } public String toString() { String toReturn; toReturn = this.title + "," + this.subject; toReturn += "," + author + "," + this.publisher; toReturn += "," + this.yearPublished + "," + this.status + "," + this.type; return toReturn; } public boolean validateDate(String date) { if(this.yearPublished == date) return true; else return false; } //compares to another person by last name public boolean compareTo(Item other) { if(!other.title.equalsIgnoreCase(this.title)) return false; else if(!other.author.equalsIgnoreCase(this.author)) return false; else return true; } //----------------------Setters and Getters---------------------- public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getSubject() { return subject; }
public void setSubject(String subject) { this.subject = subject; }
public String getAuthor() { return author; }
public void setAuthor(String author) { this.author = author; }
public String getPublisher() { return publisher; }
public void setPublisher(String publisher) { this.publisher = publisher; }
public String getYearPublished() { return yearPublished; }
public void setYearPublished(String yearPublished) { if(yearPublished.length() == 4 ); this.yearPublished = yearPublished; }
public boolean getStatus() { return status; }
public void setStatus(boolean status) { this.status = status; }
public String getType() { return type; }
public void setType(String type) { if(type.equalsIgnoreCase("book") || type.equalsIgnoreCase("cd") || type.equalsIgnoreCase("dvd") || type.equalsIgnoreCase("journal")) this.type = type; } }
import java.util.ArrayList;
public class Student { Person person; private ArrayList
import java.util.ArrayList;
public class Students { private ArrayList
import java.awt.*; import java.awt.event.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Scanner;
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.UIManager;
public class TesterClass extends JFrame { private Container contents; private JButton studentButton, administratorButton, enterButton; private JLabel studentInfo; private JTextField idInput; private JPasswordField idInputP; //lists private Administrator adminList; private Students studentList; private static Library itemList; //JPanels private StudentOptionsWindow studentOptionsPanel; private AdminOptionsPanel adminOptionsPanel; // private boolean shouldFill = true, goneBack = false; private CardLayout cardLayout = new CardLayout(); private JPanel cards = new JPanel(cardLayout); private JPanel introPanel; private TesterClass tester; public static void main(String args[]) throws FileNotFoundException, IOException { TesterClass gui = new TesterClass(); Scanner studentDoc = new Scanner(new File("students.txt")); Scanner adminDoc = new Scanner(new File("administrators.txt")); Scanner itemDoc = new Scanner(new File("items.txt")); gui.studentList = new Students(); gui.adminList = new Administrator(); gui.itemList = new Library(); gui.fillStudentsArray(gui.studentList, studentDoc); gui.fillAdminArray(gui.adminList, adminDoc); // gui.fillItemArray(itemList, itemDoc); try { // serialize(itemList); deserialize(); } catch(Exception e) { System.out.println("fdasdfa"); } } public TesterClass() throws FileNotFoundException { super("Library Application"); contents = getContentPane(); introPanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); tester = this; if (shouldFill) { //natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } studentButton = new JButton("Student"); studentButton.setBackground(Color.decode("#7ec0ee")); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; c.weightx = 0.5; c.gridx = 0; c.gridy = 0; introPanel.add(studentButton, c); administratorButton = new JButton("Administrator"); administratorButton.setBackground(Color.decode("#7ec0ee")); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; c.weightx = 0.5; c.gridx = 1; c.gridy = 0; introPanel.add(administratorButton, c); enterButton = new JButton(""); enterButton.setBackground(Color.decode("#98ff98")); idInputP = new JPasswordField(0); //Add labels after selection studentInfo = new JLabel(""); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; //make this component tall c.weightx = 1.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 1; introPanel.add(studentInfo, c); ButtonHandler bh = new ButtonHandler(); studentButton.addActionListener(bh); administratorButton.addActionListener(bh); enterButton.addActionListener(bh); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; //make this component tall c.weightx = 0.5; c.gridx = 0; c.gridy = 5; introPanel.setBackground(Color.white); //Add all the cards to cardLayout!!!------------- cards.add(introPanel, "intro"); contents.add(cards); setSize(300, 300); setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private class ButtonHandler implements ActionListener { boolean studentButtonPressed, adminButtonPressed; public void actionPerformed(ActionEvent action) { GridBagConstraints c = new GridBagConstraints(); if(action.getSource() == studentButton) { adminButtonPressed = false; studentInfo.setText("Please enter your Student I.D."); //add the input option idInputP.setColumns(10); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 40; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 2; introPanel.add(idInputP, c); enterButton.setText("Enter"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 3; introPanel.add(enterButton, c); studentButtonPressed = true; } if(action.getSource() == administratorButton) { studentButtonPressed = false; studentInfo.setText("Please enter your Administrator I.D."); //add the input option idInputP.setColumns(10); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 40; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 2; introPanel.add(idInputP, c); enterButton.setText("Enter"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 20; //make this component tall c.weightx = 0.0; c.gridwidth = 3; c.gridx = 0; c.gridy = 3; introPanel.add(enterButton, c); adminButtonPressed = true; } if(action.getSource() == enterButton) { String id = idInputP.getText(); if(goneBack == true) { try { serialize(itemList); } catch(Exception e) { System.out.println("fdasdfa"); } enterButton.setText("Enter"); } if(studentList.searchStudent(id) && studentButtonPressed == true && goneBack == false) { studentOptionsPanel = new StudentOptionsWindow (studentList.getStudentArray().get(studentList.getIndexofMatch(id))); cards.add(studentOptionsPanel, "studentOption"); studentOptionsPanel.itemList = itemList; studentOptionsPanel.currentStudent = studentList.getStudentArray().get(studentList.getIndexofMatch(id)); studentOptionsPanel.setTester(tester); swapView("studentOption"); setSize(400, 400); idInputP.setText(""); enterButton.setText("Save"); goneBack = true; } else if(adminList.searchAdmin(id) && adminButtonPressed == true && goneBack == false) { adminOptionsPanel = new AdminOptionsPanel(); cards.add(adminOptionsPanel, "adminOption"); adminOptionsPanel.itemList = itemList; adminOptionsPanel.studentList = studentList; adminOptionsPanel.setTester(tester); swapView("adminOption"); setSize(400, 400); idInputP.setText(""); goneBack = true; enterButton.setText("Save"); } else { JOptionPane error = new JOptionPane(); if(goneBack == false)error.showMessageDialog(null, "Invalid ID"); if(goneBack == true)error.showMessageDialog(null, "Data Saved"); goneBack = false; idInputP.setText(""); } } } } public void fillStudentsArray(Students studentList, Scanner studentDoc) throws FileNotFoundException { String line= "", name = "", lastName = "", id = "", email = "", phone = ""; while(studentDoc.hasNextLine()) { line = studentDoc.nextLine(); Scanner currentLine = new Scanner(line); while(currentLine.hasNext()) { name = currentLine.next(); lastName = currentLine.next(); id = currentLine.next(); email = currentLine.next(); phone = currentLine.next(); studentList.add(new Student(new Person(name, lastName, id,email ,phone ))) ; } } }
public void fillAdminArray(Administrator adminList, Scanner studentDoc) throws FileNotFoundException { String line= "", name = "", lastName = "", id = "", email = "", phone = ""; while(studentDoc.hasNextLine()) { line = studentDoc.nextLine(); Scanner currentLine = new Scanner(line); while(currentLine.hasNext()) { name = currentLine.next(); lastName = currentLine.next(); id = currentLine.next(); email = currentLine.next(); phone = currentLine.next(); adminList.add(new Person(name, lastName, id,email ,phone )) ; } } } public void fillItemArray(Library itemList, Scanner itemDoc) { String line = "", title = "", subject = "", author = "", publisher = "", yearPublished = "", type = ""; boolean status; while(itemDoc.hasNextLine()) { line = itemDoc.nextLine(); Scanner currentLine = new Scanner(line); currentLine.useDelimiter(","); title = currentLine.next(); subject = currentLine.next(); author = currentLine.next(); publisher = currentLine.next(); yearPublished = currentLine.next(); status = Boolean.parseBoolean(currentLine.next()); type = currentLine.next(); itemList.add(new Item(title, subject, author, publisher , yearPublished, status, type )) ; } }//end of fill item array public static void serialize(Library p) throws Exception { ObjectOutputStream cout = null; try { OutputStream outputFile = new FileOutputStream( "Serialized" ); //object output stream allows you to output an object as a whole cout = new ObjectOutputStream( outputFile ); cout.writeObject(p); } catch ( IOException ioException ) { System.err.println( "****Error opening file." ); } cout.close(); } public static void deserialize() throws Exception { // p= new ArrayList }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
