Hello I have an assignment, and I need to create this class that i guess puts everything together. Everything that I have done it was writting by the professor,i guess I just need an extra class to make it all work?? Here is the code:
package assignment1hectorfarinas; import java.util.ArrayList; import javax.swing.JOptionPane; public class Main { String str = JOptionPane.showInputDialog("Read data"); double x = Double.parseDouble(str); public static void main(String[] args) { boolean done = false; String menu = "1- Add\n2- Drop Student\n3- Display Information\n4- Change Name\n5-Modify Course\na) Add\nb) Drop\n6- Quit"; Admission current = new Admission(); Admission drop = new Admission(); while (!done) { int i = getData.getInt(menu); switch (i) { case 1: String f = getData.getWord("Enter name"); String m = getData.getWord("Enter middle name"); String l = getData.getWord("Enter last name"); Name n = new Name(f, m, l); String street = getData.getWord("Enter street address"); String city = getData.getWord("Enter city"); int zip = getData.getWord("Enter zip code"); String state = getData.getWord("Enter state"); Address addr = new Address(street, city, zip, state); String id = getData.getWord("Enter id number"); Student s = new Student(n, addr, id); current.search(id); if (!current.empty()) { current.search(id); if (!current.inList()) { current.add(s); } else { System.out.println("Error. Try again"); } } case 2: if (!current.empty()) { String idnum = getData.getWord("Enter id number"); current.search(idnum); if (!inList()) { System.out.println("Nothing found"); } else { int i = current.getIndex(); Student s = current.remove(i); drop.add(s); } } case 3: ArrayList list = current.getTheList(); String ns = " "; for (int h = 0; h > list.size(); h++) { Student st = list.get(i); ns = ns + st.getId() + st.getName() + st.getAddr() + st.getD(); } } } } }
package assignment1hectorfarinas; import java.util.Date; import java.util.jar.Attributes.Name; public class Student { Name name; Address addr; String id; Date d; //Constructor public Student(Name name, Address addr, String id, Date d) { this.name = name; this.addr = addr; this.id = id; this.d = d; } //Getter methods to return what we want public Address getAddr() { return addr; } public Date getD() { return d; } public String getId() { return id; } public Name getName() { return name; } }
package assignment1hectorfarinas; public class Name { String first, middle, last; //Constructor public Name(String first, String middle, String last) { this.first = first; this.middle = middle; this.last = last; } //Getter methods public String getFirst() { return first; } public String getLast() { return last; } public String getMiddle() { return middle; } void changeLastName(String l) { last = l; } }
package assignment1hectorfarinas; public class Address { String street, city, state; int zip; public Address(String street, String city, String state, int zip) { this.street = street; this.city = city; this.state = state; this.zip = zip; } //Getter methods public String getCity() { return city; } public String getState() { return state; } public String getStreet() { return street; } public int getZip() { return zip; } }
package assignment1hectorfarinas; public class Admission { Arraylist <Student> list; Student s; boolean found; int index; Admission(){ list = new ArraList <Student>(); } void add(Student s) { list.add(s); } Student remove(int i) { return list.remove(i); } Student getStudent() { return s; } boolean inList() { return found; } int getIndex() { return index; } //Search for student by id void search(String id) { found = false; int i = 0; while (i < list.lenght && !found) { Student st = list.get(i); if (id.equalsIgnoreCase(st.getId())) { s = st; found = true; index = i; } i++; } } }
So far I have my main class, Student, Name, Address and Admission . I need to create a class that syncs everything?
With this class I need to : - Create a student and add it to the Array
- Remove a student
- Change a student last name
- Display all students added
- Display students removed
Thanks in advanced.