Question

In: Computer Science

Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in...

Required Tasks:

  1. In Eclipse, create a Java Project as CS-176L-Assign5.
  2. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java.
  3. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method.
  4. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp
  5. In StudentList.java, create two new public methods:
    1. The addStudent method should have one parameter of type Student and should add the given Student to the StudentList.
    2. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList.
  6. In Assign5Test.java do the following:
    1. Create a new StudentList containing 3 students.
    2. Print the info of all the Students in the StudentList using the getAllStudentInfo method.
    3. Remove one Student from the StudentList using the removeStudent method.
    4. Add two new Students to the StudentList using the addStudent method.
    5. Print the info of all the Students in the StudentList using the getAllStudentInfo method. Notice that one Student was removed and two were added.
  7. Code must compile and run without warnings or errors.
  8. Final output should look something like the following:

Name: [Abdulmuhsin J.Al-Kandari], Email: [[email protected]], Major: [SE], GraduationYear: [2017]

Name: [Justin R. Schlemm], Email: [[email protected]], Major: [SE], GraduationYear: [2016]

Name: [Mary F. Menges], Email: [[email protected]], Major: [SE], GraduationYear: [2017]

Name: [Abdulmuhsin J.Al-Kandari], Email: [[email protected]], Major: [SE], GraduationYear: [2017]

Name: [Justin R. Schlemm], Email: [[email protected]], Major: [SE], GraduationYear: [2016]

Name: [Nicholas-Jason R. Roache], Email: [[email protected]], Major: [CS], GraduationYear: [2017]

Name: [Taylor J. Klodowski], Email: [[email protected]], Major: [SE], GraduationYear: [2016]

Solutions

Expert Solution

Implementation of above program in JAVA:

import java.util.ArrayList;
import java.util.Scanner;

//class Assign5Test.java
public class Assign5Test {

//   Scanner class declared as Static
   static Scanner s= new Scanner(System.in);
  
//   driver method
   public static void main(String[] args) {
  
       StudentList sl = new StudentList();
      
       System.out.println("Add 3 Students :");
       System.out.println();
      
       add(sl);
       add(sl);
       add(sl);
       System.out.println();
       print(sl.list);
       System.out.println();
       System.out.println("Remove 1 Student : ");
       remove(sl);
       System.out.println();
       System.out.println("Add 2 Students :");
       System.out.println();
       add(sl);
       add(sl);
       System.out.println();
       print(sl.list);

   }
  
//   print the list by using the object of StudentList
//   and getters of Student class
   public static void print(ArrayList<Student1> list) {
      
       System.out.println("-------------------List of Students-----------------");
       System.out.println();
      
      
       for(int i=0;i<list.size();i++) {
          
           Student1 st= list.get(i);
          
   System.out.println("Name: ["+st.getname()+"], Email: ["+st.getemail()+"], Major: ["+st.getmajor()+"], Graduation Year: ["+st.getyear()+"]");      
       }
   }
  
//   user enter input and call add method in StudentList class
   public static void add(StudentList sl) {
      
      
       System.out.print("Enter the name of Student : ");
       String name=s.next();
       s.nextLine();
       System.out.print("Enter the Email of Student : ");
       String email=s.next();
       s.nextLine();
       System.out.print("Enter the major of Student : ");
       String major=s.next();
       s.nextLine();
       System.out.print("Enter the Graduation-Year of Student : ");
       String year=s.next();
       s.nextLine();
      
       Student1 st= new Student1(name,email,major,year);
      
         
       sl.addstudent(st);
   }
  
//   user enter input and call remove method in StudentList class
   public static void remove(StudentList sl) {
      
       System.out.print("Enter the Email of Student you want to remove : ");
       String email=s.next();
         
       sl.remove(email);
   }

}

//----------------------------------------------------

// class StudentList.java
class StudentList{
  
//   Arraylist
   ArrayList<Student1> list= new ArrayList<Student1>();
  
//   add Student in arrayList
   public void addstudent(Student1 st) {
      
      
       list.add(st);
       System.out.println("Student Added!!!");
       System.out.println();
   }
  
//       remove Student in arrayList
   public void remove(String email) {
      
//       traverse whole list and try to found mail if dound then remove
//       else print "Email not found..."
       for(int i=0;i<list.size();i++) {
          
           Student1 st=list.get(i);
          
           if(st.getemail().equals(email)) {
               list.remove(i);
               System.out.println("Student removed!!!");
               return;
           }
          
       }
      
       System.out.println("Email not found...");
      
   }
  
  
  
}

//--------------------------------------------------------


//class Student1.java
class Student1{
  
   String name;
   String email;
   String major;
   String year;
  
//   Constructor
public Student1(String name, String email ,String major, String year) {
   this.name=name;
   this.email=email;
   this.major=major;
   this.year=year;
  
}
  
// getters Methods
public String getname() {
   return name;
}
  
public String getemail() {
   return email;
}
public String getmajor() {
   return major;
}
public String getyear() {
   return year;
}
  
  
}

SAMPLE OUTPUTS;

If you have any doubt regarding this question ask me in comments

//THANK YOU:-)


Related Solutions

JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign4Test.java. Copy your code from Assignment 3 into the Student.java and StudentList.java. Assign4Test.java should contain the main method. In Student.java, add a new private variable of type Integer called graduationYear. In Student.java, create a new public setter method setGraduationYear to set the graduationYear. The method will have one parameter of type Integer. The method will set...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
For this coding exercise, you need to create a new Java project in Eclipse and finish...
For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and paste the java source code of each file from Eclipse into the answer area of the corresponding box below. The boxes will expand once you paste your code into them, so don’t worry about how it looks J All data members are...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java,...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java, BubbleSortTestCaseMaker.java, and Statistician.java. PART 1: Implementing BubbleSorter Implement a very simple BubbleSorter class that records how many array visits and how many swaps are performed. Look at the starter file before reading on. This class has an instance variable called “a”. Its type is int[]. This is the array that will be bubble-sorted in place. Usually a single letter is a bad variable name,...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
Java Project Tasks: Create a Coin.java class that includes the following:             Takes in a coin...
Java Project Tasks: Create a Coin.java class that includes the following:             Takes in a coin name as part of the constructor and stores it in a private string             Has a method that returns the coins name             Has an abstract getvalue method Create four children classes of Coin.java with the names Penny, Nickle, Dime, and Quarter that includes the following:             A constructor that passes the coins name to the parent             A private variable that defines the...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy. In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for...
open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You need to create two classes, one for BankAccount (BankAccount.java) and the other for the tester (BankAccountTest.java). Make sure your program compile without errors before submitting. Submit .java files to eCampus by the end of next Thursday, 10/15/2020. Part 1: Create the BankAccount class (template is attached after the project description) in the project. You must add the following to the BankAccount class: An instance...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT