Analyze the code to determine what the code does, how the data is structured, and why it is the appropriate data structure (i.e. linked list, stack or queue). Note that these are examples of classes and methods and do not include the "main" or "test" code needed to execute. When you are done with your analysis, add a header describing the purpose of the program (include a description of each class and method), the results of your analysis, and add detailed explanatory comments to the code. Then submit the updated file with your revisions (comments and header).
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class ProgramOfStudy implements Iterable<Course>, Serializable
{
private List<Course> list;
public ProgramOfStudy()
{
list = new LinkedList<Course>();
}
public void addCourse(Course course)
{
if (course != null)
list.add(course);
}
public Course find(String prefix, int number)
{
for (Course course : list)
if (prefix.equals(course.getPrefix()) &&
number == course.getNumber())
return course;
return null;
}
public void addCourseAfter(Course target, Course newCourse)
{
if (target == null || newCourse == null)
return;
int targetIndex = list.indexOf(target);
if (targetIndex != -1)
list.add(targetIndex + 1, newCourse);
}
public void replace(Course target, Course newCourse)
{
if (target == null || newCourse == null)
return;
int targetIndex = list.indexOf(target);
if (targetIndex != -1)
list.set(targetIndex, newCourse);
}
public String toString()
{
String result = "";
for (Course course : list)
result += course + "\n";
return result;
}
public Iterator<Course> iterator()
{
return list.iterator();
}
public void save(String fileName) throws IOException
{
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
}
public static ProgramOfStudy load(String fileName) throws IOException, ClassNotFoundException
{
FileInputStream fis = new FileInputStream(fileName);
ObjectInputStream ois = new ObjectInputStream(fis);
ProgramOfStudy pos = (ProgramOfStudy) ois.readObject();
ois.close();
return pos;
}
}
Analyze the code to determine what the code does, how the data is structured, and why...
I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...
Can someone please explain this piece of java code line by line as to what they are doing and the purpose of each line (you can put it in the code comments). Code: import java.util.*; public class Array { private Integer[] array; // NOTE: Integer is an Object. Array() { super(); array = new Integer[0]; } Array(Array other) { super(); array = other.array.clone(); // NOTE: All arrays can be cloned. } void add(int value) { ...
Please help complete the items marked TODO in the code and get the tests to pass: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestIterator { private List<Integer> list; // See the Java List Interface documentation to understand what all the List methods do ... @Before public void setUp() throws Exception { list = new ArrayList<Integer>(); // TODO also try with a...
Can someone help me to figure that error I have put below. JAVA ----jGRASP exec: javac -g P4Program.java P4Program.java:94: error: package list does not exist Iterator i = new list.iterator(); ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. Note: Below there are two different classes that work together. Each class has it's own fuctions/methods. import java.util.*; import java.io.*; public class P4Program{ public void linkedStackFromFile(){ String content = new String(); int count = 1; File...
Problem: Use the code I have provided to start writing a program that accepts a large file as input (given to you) and takes all of these numbers and enters them into an array. Once all of the numbers are in your array your job is to sort them. You must use either the insertion or selection sort to accomplish this. Input: Each line of input will be one item to be added to your array. Output: Your output will...
Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to both classes: public void reverseThisList(), This method will reverse the lists. When testing the method: print out the original list, call the new method, then print out the list again ------------------------------------------------------------------------- //ARRAY LIST class: public class ArrayList<E> implements List<E> { /** Array of elements in this List. */ private E[] data; /** Number of elements currently in this List. */ private int size; /**...
public class File { public String base; //for example, "log" in "log.txt" public String extension; //for example, "txt" in "log.txt" public int size; //in bytes public int permissions; //explanation in toString public String getExtension() { return extension; } public void setExtension(String e) { if(e == null || e.length() == 0) extension = "txt"; else extension = e; } public class FileCollection { private File[] files; /** * DO NOT MODIFY * Loads collection from input file * @param input: name...
Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...
1. What does the following code print to the console? LocalDate date = LocalDate.of(1976, Month.JANUARY, 1); DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); System.out.println(dtf.format(date)); a. 01/01/1976 b. Jan 1, 1976 c. 1976-01-01 d. 01/01/76 2. What is the value of s2 after the code that follows is executed? String s1 = "118-45-9271"; String s2 = ""; for (int i = 0; i < s1.length(); i++) { if (s1.charAt(i) != '-') { s2 += s1.charAt(i); } } s2 = s2.replace('-', '.'); a....
How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar { public static final String COURSES_FILE = "Courses.csv"; public static final String STUDENTS_FILE = "Students.csv"; public static final String PATH = System.getProperty("java.class.path"); /** * Hash table to store the list of students using their...