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...
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,...
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...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
PLZ USE JAVA ECLIPSE AND EXPLAIN Create a GUI which works as an accumulator:  There...
PLZ USE JAVA ECLIPSE AND EXPLAIN Create a GUI which works as an accumulator:  There is a textfield A which allows user to enter a number  There is also another textfield B with value start with 0.  When a user is done with entering the number in textfield A and press enter, calculate the sum of the number in textfield B and the number user just entered in textfield A, and display the updated number in textfield...
JAVA Practice Exam 2 The project practice_exam_2 contains three (3) classes: Testing – This is the...
JAVA Practice Exam 2 The project practice_exam_2 contains three (3) classes: Testing – This is the file you will use to execute your program and test your cases. Each section refers to one or more specific array(s). From here, you can run the whole program or one section at a time. TestCases – This file contains all test cases. NO NEED FOR YOU TO PAY ATTENTION TO IT. YourCode – This is where you will be writing your code. Implement...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a new project in BlueJ. Create two new classes in the project, with the following...
Create a new project in BlueJ. Create two new classes in the project, with the following specifications: Class name: Part Fields: id (int) description (String) price (double) onSale (boolean) 1 Constructor: takes parameters partId, partDescrip, and partPrice to initialize fields id, description, and price; sets onSale field to false. Methods: Write get-methods (getters) for all four fields. The getters should be named getId, getDescription, getPrice, and isOnSale.
Create a moderately complex java program that utilises 2 or more classes. Within these classes: -...
Create a moderately complex java program that utilises 2 or more classes. Within these classes: - have one that defines an exception - have that exception throw(n) in one method and handled in another -has the program continue even if the user inputs incorrect data -be creative/unique in some way
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT