Question

Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a progr

3. Your program must contain a Student class, which contains following properties id: int, firstName: String, lastName: Strin

Hw08FinalProjectStudentList.txt: (Data structure is Array List)

1,Simon,Jefferson,gy3085,4.0,2019
2,John,Johnson,xy1242,3.9,2019
3,Kayla,Anderson,as1324,3.8,2019
4,David,Kidman,re5423,3.8,2017
5,Mary,Coleman,ze7698,3.8,2018

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

Hw08FinalProjectStudentList.txt (Input file)

1,Simon,Jefferson,gy3085,4.0,2019
2,John,Johnson,xy1242,3.9,2019
3,Kayla,Anderson,as1324,3.8,2019
4,David,Kidman,re5423,3.8,2017
5,Mary,Coleman,ze7698,3.8,2018

======================================

// Student.java

public class Student implements Comparable<Student>{
   private int id;
   private String firstName;
   private String lastName;
   private String accessId;
   private double gpa;
   private int entranceYear;

   /**
   * @param id
   * @param firstName
   * @param lastName
   * @param accessId
   * @param gpa
   * @param entranceYear
   */
   public Student(int id, String firstName, String lastName, String accessId,
           double gpa, int entranceYear) {
       this.id = id;
       this.firstName = firstName;
       this.lastName = lastName;
       this.accessId = accessId;
       this.gpa = gpa;
       this.entranceYear = entranceYear;
   }

   /**
   * @return the id
   */
   public int getId() {
       return id;
   }

   /**
   * @param id
   * the id to set
   */
   public void setId(int id) {
       this.id = id;
   }

   /**
   * @return the firstName
   */
   public String getFirstName() {
       return firstName;
   }

   /**
   * @param firstName
   * the firstName to set
   */
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   /**
   * @return the lastName
   */
   public String getLastName() {
       return lastName;
   }

   /**
   * @param lastName
   * the lastName to set
   */
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   /**
   * @return the accessId
   */
   public String getAccessId() {
       return accessId;
   }

   /**
   * @param accessId
   * the accessId to set
   */
   public void setAccessId(String accessId) {
       this.accessId = accessId;
   }

   /**
   * @return the gpa
   */
   public double getGpa() {
       return gpa;
   }

   /**
   * @param gpa
   * the gpa to set
   */
   public void setGpa(double gpa) {
       this.gpa = gpa;
   }

   /**
   * @return the entranceYear
   */
   public int getEntranceYear() {
       return entranceYear;
   }

   /**
   * @param entranceYear
   * the entranceYear to set
   */
   public void setEntranceYear(int entranceYear) {
       this.entranceYear = entranceYear;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Id=" + id + ", firstName=" + firstName + ", lastName="
               + lastName + ", accessId=" + accessId + ", gpa=" + gpa
               + ", entranceYear=" + entranceYear;
   }

   @Override
   public int compareTo(Student other) {
       if(this.firstName.compareTo(other.getFirstName())<0)
           return -1;
       else if(this.firstName.compareTo(other.getFirstName())>0)
           return 1;
       return 0;
   }

}

==============================================

// StudentDAO.java

public interface StudentDAO {
void addNewStudent(Student s);
void editStudentByID(int id);
void showStudentList();
void deleteStudentByID(int id);
void findStudentByID(int id);
void findStudentByFirstName(String fname);
void findStudentByLastName(String lname);
  
}

=================================================

// StudentDAOImpl.java

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class StudentDAOImpl implements StudentDAO {
   private ArrayList<Student> students;

   public StudentDAOImpl() {
       students = new ArrayList<Student>();
   }

   @Override
   public void addNewStudent(Student s) {
       students.add(s);

   }

   @Override
   public void editStudentByID(int id) {
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
       int index = isStudentAvailable(id);
       if (index == -1) {
           System.out.println("Student Not Found");
       } else {
           System.out.print("Enter firstname :");
           String fname = sc.next();

           System.out.print("Enter lastname :");
           String lname = sc.next();

           System.out.print("Enter access ID :");
           String accessID = sc.next();

           System.out.print("Enter Gpa :");
           double gpa = sc.nextDouble();

           System.out.print("Enter Entrance year :");
           int year = sc.nextInt();

           Student s = new Student(id, fname, lname, accessID, gpa, year);
           students.set(index, s);
           System.out.println("** Student Successfully Modified **");

       }

   }

   private int isStudentAvailable(int id) {
       for (int i = 0; i < students.size(); i++) {
           if (students.get(i).getId() == id)
               return i;
       }
       return -1;
   }

   @Override
   public void showStudentList() {
       for(int i=0;i<students.size();i++)
       {
           System.out.println(students.get(i));
       }

   }

   @Override
   public void deleteStudentByID(int id) {
       int index = isStudentAvailable(id);
       if (index == -1) {
           System.out.println("Student Not Found");
       } else {
           students.remove(index);
           System.out.println("** Student Successfully Deleted **");
       }
      

   }

   @Override
   public void findStudentByID(int id) {
       int index = isStudentAvailable(id);
       if (index == -1) {
           System.out.println("Student Not Found");
       } else {
           System.out.println(students.get(index));
       }

   }

   @Override
   public void findStudentByFirstName(String fname) {
       int flag=0;
       for(int i=0;i<students.size();i++)
       {
           if(students.get(i).getFirstName().equalsIgnoreCase(fname))
           {
               System.out.println(students.get(i));
           flag=1;
           }
       }
       if(flag==0)
           System.out.println("Student not found");

   }

   @Override
   public void findStudentByLastName(String lname) {
       int flag=0;
       for(int i=0;i<students.size();i++)
       {
           if(students.get(i).getLastName().equalsIgnoreCase(lname))
           {
               System.out.println(students.get(i));
       flag=1;
           }
       }
       if(flag==0)
           System.out.println("Student not found");
   }

   public void save() throws IOException
   {
       FileWriter fw = new FileWriter(new File("Hw08FinalProjectStudentList.txt"));
       for(int i=0;i<students.size();i++)
       {
           fw.write(students.get(i).getId()+","+students.get(i).getFirstName()+","+students.get(i).getLastName()+","+students.get(i).getAccessId()+","+students.get(i).getGpa()+","+students.get(i).getEntranceYear()+"\n");
       }
       fw.close();
   }
}


=============================================

// Hw08FinalProject.java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Hw08FinalProject {

   public static void main(String[] args) throws IOException {
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner read = new Scanner(System.in);
       int id, choice = 0;
       String firstName, lastName, accessId, choice1;
       double gpa;
       int entranceYear;
       StudentDAOImpl simpl = new StudentDAOImpl();

       try {
           Scanner sc = new Scanner(
                   new File("Hw08FinalProjectStudentList.txt"));
           while (sc.hasNext()) {
               String line = sc.nextLine();
               String arr[] = line.split(",");
               id = Integer.parseInt(arr[0]);
               firstName = arr[1];
               lastName = arr[2];
               accessId = arr[3];
               gpa = Double.parseDouble(arr[4]);
               entranceYear = Integer.parseInt(arr[5]);
               Student s = new Student(id, firstName, lastName, accessId, gpa,
                       entranceYear);
               simpl.addNewStudent(s);
           }

           sc.close();
          

           while (true) {
               System.out.println("\n1.Show Student List");
               System.out.println("2.Add a new Student");
               System.out.println("3.Edit a Student by Id");
               System.out.println("4.Delete a Student");
               System.out.println("5.Find a Student by ID");
               System.out.println("6.Find a Student(s) by First Name");
               System.out.println("7.Find a srudent(s) by Last Name");
               System.out.println("Please q to exit or Press (1-7) :");
               choice1 = read.next();
               if (choice1.equalsIgnoreCase("q")) {
               simpl.save();
                   break;
               } else {
                   choice = Integer.parseInt(choice1);
                   switch (choice) {
                   case 1: {
                       simpl.showStudentList();
                       continue;
                   }
                   case 2: {
                      

                       System.out.print("Enter Id :");
                       int ID = read.nextInt();
                      
                       System.out.print("Enter firstname :");
                       String fname = read.next();

                       System.out.print("Enter lastname :");
                       String lname = read.next();

                       System.out.print("Enter access ID :");
                       String accessID = read.next();

                       System.out.print("Enter Gpa :");
                       gpa = read.nextDouble();

                       System.out.print("Enter Entrance year :");
                       int year = read.nextInt();

                       Student s = new Student(ID, fname, lname, accessID, gpa, year);
                       simpl.addNewStudent(s);
                      
                       continue;
                   }
                   case 3: {

                       System.out.print("Enter Student Id :");
                       id = read.nextInt();
                      
                       simpl.editStudentByID(id);
                       continue;
                   }
                   case 4: {
                       System.out.print("Enter Student Id :");
                       id = read.nextInt();
                      
                       simpl.deleteStudentByID(id);
                       continue;
                   }
                   case 5: {
                       System.out.print("Enter Student Id :");
                       id = read.nextInt();
                      
                       simpl.findStudentByID(id);
                       continue;
                   }
                   case 6: {
                       System.out.print("Enter firstname :");
                       firstName = read.next();
                      
                       simpl.findStudentByFirstName(firstName);
                       continue;
                   }
                   case 7: {
                       System.out.print("Enter lastname :");
                       lastName = read.next();
                      
                       simpl.findStudentByLastName(lastName);
                       continue;
                   }

                   }
               }
           }

       } catch (FileNotFoundException e) {
           System.out.println(e.getMessage());
       }

   }

}
==============================================

Output:


1.Show Student List
2.Add a new Student
3.Edit a Student by Id
4.Delete a Student
5.Find a Student by ID
6.Find a Student(s) by First Name
7.Find a srudent(s) by Last Name
Please q to exit or Press (1-7) :
1
Id=1, firstName=Simon, lastName=Jefferson, accessId=gy3085, gpa=4.0, entranceYear=2019
Id=2, firstName=John, lastName=Johnson, accessId=xy1242, gpa=3.9, entranceYear=2019
Id=3, firstName=Kayla, lastName=Anderson, accessId=as1324, gpa=3.8, entranceYear=2019
Id=4, firstName=David, lastName=Kidman, accessId=re5423, gpa=3.8, entranceYear=2017
Id=5, firstName=Mary, lastName=Coleman, accessId=ze7698, gpa=3.8, entranceYear=2018

1.Show Student List
2.Add a new Student
3.Edit a Student by Id
4.Delete a Student
5.Find a Student by ID
6.Find a Student(s) by First Name
7.Find a srudent(s) by Last Name
Please q to exit or Press (1-7) :
2
Enter Id :6
Enter firstname :Pat
Enter lastname :Simkox
Enter access ID :ze5467
Enter Gpa :3.4
Enter Entrance year :2019

1.Show Student List
2.Add a new Student
3.Edit a Student by Id
4.Delete a Student
5.Find a Student by ID
6.Find a Student(s) by First Name
7.Find a srudent(s) by Last Name
Please q to exit or Press (1-7) :
4
Enter Student Id :2
** Student Successfully Deleted **

1.Show Student List
2.Add a new Student
3.Edit a Student by Id
4.Delete a Student
5.Find a Student by ID
6.Find a Student(s) by First Name
7.Find a srudent(s) by Last Name
Please q to exit or Press (1-7) :
1
Id=1, firstName=Simon, lastName=Jefferson, accessId=gy3085, gpa=4.0, entranceYear=2019
Id=3, firstName=Kayla, lastName=Anderson, accessId=as1324, gpa=3.8, entranceYear=2019
Id=4, firstName=David, lastName=Kidman, accessId=re5423, gpa=3.8, entranceYear=2017
Id=5, firstName=Mary, lastName=Coleman, accessId=ze7698, gpa=3.8, entranceYear=2018
Id=6, firstName=Pat, lastName=Simkox, accessId=ze5467, gpa=3.4, entranceYear=2019

1.Show Student List
2.Add a new Student
3.Edit a Student by Id
4.Delete a Student
5.Find a Student by ID
6.Find a Student(s) by First Name
7.Find a srudent(s) by Last Name
Please q to exit or Press (1-7) :
q

=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Hw08FinalProjectStudentList.txt: (Data structure is Array List) 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hw08FinalProjectStudentList.txt 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall

    Hw08FinalProjectStudentList.txt 1,Simon,Jefferson,gy3085,4.0,2019 2,John,Johnson,xy1242,3.9,2019 3,Kayla,Anderson,as1324,3.8,2019 4,David,Kidman,re5423,3.8,2017 5,Mary,Coleman,ze7698,3.8,2018 Description: This assignment is going to evaluate your overall knowledge of the Java Programming. You shall implement a program which can store and retrieve student list. The program has a menu that you can take input from console, and the user can choose between the items. The program data is in the HwO8FinalProjectStudentList.txt file. Required Items: 1. The program must show a menu to user and ask the user can either choose between the...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Need help working through CLion: Description: For this assignment you will create a program to manage...

    Need help working through CLion: Description: For this assignment you will create a program to manage phone contacts. Your program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2....

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • Write a Java program that allows the following: 1.Create an array list of 20 integers. The...

    Write a Java program that allows the following: 1.Create an array list of 20 integers. The 20 integers are generated randomly with possible values from 0 to 10. 2.Print the content of the array list. 3.Find how many of these values are multiple of 3. Show a screenshot of the output with your name and Id in the first line (if there is no screenshot of the output, the student shall get a zero mark for this question). Program typical...

  • Information About This Project             In the realm of database processing, a flat file is a...

    Information About This Project             In the realm of database processing, a flat file is a text file that holds a table of records.             Here is the data file that is used in this project. The data is converted to comma    separated values ( CSV ) to allow easy reading into an array.                         Table: Consultants ID LName Fee Specialty 101 Roberts 3500 Media 102 Peters 2700 Accounting 103 Paul 1600 Media 104 Michael 2300 Web Design...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT