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: String,

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

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 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
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: (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

    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 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...

  • 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...

  • Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person...

    Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...

  • 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 =...

  • This assignment involves 2 Java programs 1) Write a Java program to read a CSV (Comma...

    This assignment involves 2 Java programs 1) Write a Java program to read a CSV (Comma separated values) text file. The text file will contain comma separated values in each line. Each line contains data in this format: String(20), String(5),String(10), double. There will be multiple lines with each line containing the same number of values. Ask the user to enter the path for the CSV file for reading the file. After reading the data from the file output the data...

  • Language Java Step 1: Design a class called Student. The Student class should contain the following...

    Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...

  • 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,...

  • 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...

  • Modify your inventory management system created in previous assignment (assignments 2) to use dynamic memory allocation...

    Modify your inventory management system created in previous assignment (assignments 2) to use dynamic memory allocation (instead of the fixed size array) and files to store the inventory information, so that there is no limitation on how much items your application could support and user doesn’t need to input the data over and over again. assignment2 Your application shall maintain the following information regarding an item. Item ID – unsigned long Item name – string Item cost – float Quantity...

  • 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...

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