Question

In: Computer Science

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 the Student object’s graduationYear to the passed in value.

In Student.java, create a new public getter method getGraduationYear to get the graduationYear. The method will have no parameters. The method will return the Student object’s graduationYear.

In Student.java, modify the Student Class Constructor method to accept graduationYear as a parameter. Assign the initial value for the graduationYear variable in the Constructor method.

In Student.java, modify the toString method to add graduationYear to the String containing the other student info. Make sure the format of the String remains consistent.
In StudentList.java, add a new method as follows:
public boolean updateStudentGraduationYear (String email, Integer year) {...}

This method should implement the Java code to search through the studentArray to find the student based on given email. If a student is found, call the setGraduationYear method in the Student Class to update the Student’s graduation year. The return value should be true or false based on if the student was found and the graduation year updated.

In Assign4Test.java, create 3 students with graduation year 2022. Create a StudentList containing these 3 students (look at the code in Assign2Test or Assign3Test to figure out how to do this).
In Assign4Test.java, Print the info of all the Students in the StudentList using the getAllStudentInfo method. Update the graduation year of one of the Students to 2021 using the updateStudentGraduationYear method. Again print the info of all the Students in the StudentList using the getAllStudentInfo method to verify that the graduation year was updated correctly.
Code must compile and run without warnings or errors.
Final output should look something like the following:
Name: [Abdulmuhsin J. Al-Kandari], Email: [[email protected]], Major: [SE], GraduationYear: [2022]
Name: [Justin R. Schlemm], Email: [[email protected]], Major: [SE], GraduationYear: [2022]
Name: [Mary F. Menges], Email: [[email protected]], Major: [SE], GraduationYear: [2022]

Name: [Abdulmuhsin J. Al-Kandari], Email: [[email protected]], Major: [SE], GraduationYear: [2022]
Name: [Justin R. Schlemm], Email: [[email protected]], Major: [SE], GraduationYear: [2022]
Name: [Mary F. Menges], Email: [[email protected]], Major: [SE], GraduationYear: [2021]

//*******************************************************************
// Student
// This class can be used to create a Student object having a name, an email, and a major
//*******************************************************************
public class Student {
  
   private String name;
   private String email;
   private String major;
  
   public Student(String name, String email, String major){
       setName(name);
       setEmail(email);
       setMajor(major);
   }
  
   public String getName() {
       return name;
   }
  
   public void setName(String name) {
       this.name = name;
   }
  
   public String getEmail() {
       return email;
   }
  
   public void setEmail(String email) {
       this.email = email;
   }
  
   public String getMajor() {
       return major;
   }
  
   public void setMajor(String major) {
       this.major = major;
   }
  
   public String toString(){
       return "Name: [" + this.name + "], Email: [" + this.email + "], Major: [" + this.major + "]";
   }

}

//*******************************************************************
// StudentList
// This class can be used to create a StudentList object which contains an array of Student objects
//*******************************************************************
public class StudentList {
   private static final boolean StudentInfo = false;
   private Student[] studentArray;
   public String email;

   public StudentList(Student[] studentArray){
       setStudentArray(studentArray);
   }

   public Student[] getStudentArray() {
       return studentArray;
   }

   public void setStudentArray(Student[] studentArray) {
       this.studentArray = studentArray;

   }

   public int studentCount(String major) {
       int count = 0;
       for(int i=0; i<studentArray.length; i++)
       {
           if(major.equals ( studentArray[i].getMajor()))
           {
               count++;
          
               {
              
               }
           }
       }
       return count;
  
   }      
  
   public Student getStudentInfo(String email) {
       for(int i=0;i<studentArray.length; i++)
           if(studentArray[i].getEmail()==email) {
               return studentArray[i];
              
           }
       return null;
  
  
   }
  
   public String getAllStudentInfo() {
       String returnString = "";
       for (int i=0;i<studentArray.length; i++)
       {
           returnString = returnString+studentArray[i].toString()+System.lineSeparator();
       }
       return returnString;
       }
  
      
     

   public String studentInfo(String string) {
       return null;
   }

      
   }

      


Solutions

Expert Solution

public class Student{
    private String name;
    private String email;
    private String major;
    private int graduationYear;

    public Student(String name, String email, String majaor, int graduationYear) {  // added graduation year in Constructer
        setName(name);
        setEmail(email);
        setMajor(major);
        setGraduationYear(graduationYear);
    }

    public int getGraduationYear() {    // getgraduation method
        return graduationYear;
    }

    public void setGraduationYear(int graduationYear) {     // set graduation method
        this.graduationYear = graduationYear;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    @Override
    public String toString() {
        return "Name: [" + this.name + "], Email: [" + this.email + "], Major: [" + this.major + "], GraduationYear: [" + this.graduationYear + "]"; // added graduation year to the toString method
    }
}
public class StudentList {
    private static final boolean StudentInfo = false;
    private Student[] studentArray;
    public String email;

    public StudentList(Student[] studentArray) {
        setStudentArray(studentArray);
    }

    public void setStudentArray(Student[] studentArray) {
        this.studentArray = studentArray;
    }

    public Student[] getStudentArray() {
        return studentArray;
    }

    public int studentcount(String major) {
        int count = 0;

        for(int i = 0; i < studentArray.length; i++) {
            if(major.equals(studentArray[i].getMajor())){
                count++;
            }
        }

        return count;
    }

    public Student getStudentInfo(String email) {
        for(int i = 0; i < studentArray.length; i++) {
            if(studentArray[i].getEmail() == email) {
                return studentArray[i];
            }
        }
        return null;
    }

    public String getAllStudentInfo() {
        String returnString = "";

        for(int i = 0; i < studentArray.length; i++) {
            returnString += studentArray[i].toString() + System.lineSeparator();
        }
        return returnString;
    }

    public String studentInfo(String string) {
        return null;
    }

    public boolean updateStudentGraduationYear(String email, int year) {  // added method to update the graduation year of a student using the email.

        for(int i = 0; i < studentArray.length; i++) {
            if(studentArray[i].getEmail() == email) {
                studentArray[i].setGraduationYear(year);
                return true;                                             // if found updated and returned true
            }
        }
        return false;                                                    // else false
    }
}
public class Assign4Test {
    public static void main(final String[] args) {
        Student[] studentArray = { new Student("Abdulmuhsin J.Al-Kandari", "[email protected]", "SE", 2022), new Student("Justin R. Schlemm", "[email protected]", "SE", 2022), new Student("Mary F. Menges", "[email protected]", "SE", 2022) };
        StudentList studentlist = new StudentList(studentArray); // created student list using the student array above.

        System.out.print(studentlist.getAllStudentInfo());

        studentlist.updateStudentGraduationYear("[email protected]", 2021);  // used the updategraduationyear method in the Student list class to update the graduation year of student from the list.

        System.out.print(studentlist.getAllStudentInfo());
    }
}

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...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in...
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 should add...
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...
In Java: 1) Create a new eclipse project. 2) Create a basic SWING window 3) Create...
In Java: 1) Create a new eclipse project. 2) Create a basic SWING window 3) Create a Label Called Name 4) Create a Text Field for entering the name 5) Create a Text Field for entering and email 5) Create a text area to push the results to 6) Create two buttons, one that says submit and the other that says clear. 7) When the user enters their name and email, they should press submit and see the Text area...
in java language. There are three classes for the project, and two inner classes defined in...
in java language. There are three classes for the project, and two inner classes defined in the Cuboid class. Create the following classes: •   Shape. It’s an abstract class with two abstract methods, area and perimeter. •   Rectangle. It’s a concrete class that extends Shape. Implement area() and perimeter(). Implement the compareTo(object) method to sort rectangles by area in ascending order. •   Cuboid. It’s a concrete class that extends Rectangle. A cuboid is a 3D rectangle. The shape has a...
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...
N/B: THE PROGRAMME SHOULD BE WRITTEN IN JAVA LANGUAGE CS 202 Part 1. Create a class...
N/B: THE PROGRAMME SHOULD BE WRITTEN IN JAVA LANGUAGE CS 202 Part 1. Create a class called Loan. An instance of the class can be used to calculate information about a bank loan. The class should have the following methods: a. A constructor that is passed the amount being borrowed, the annual interest rate and the number of years for repayment. b. A default constructor that initializes the amount being borrowed, the annual interest rate and the number of years...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT