1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Masteriza [31]
3 years ago
5

Now that the classList Array has been implemented, we need to create methods to access the list items.

Computers and Technology
1 answer:
natima [27]3 years ago
7 0

The following code will be applied to Create the following static methods for the Student class

<u>Explanation:</u>

/* Note: Array index starts from 0 in java so ,, user ask for 1 index then the position will be i-1 , below program is based on this concept if you dont want this way just remove -1 from classList.get(i-1).getName(); ,and classList.add(i-1,student); */

/* ClassListTester.java */

public class ClassListTester

{

public static void main(String[] args)

{

//You don't need to change anything here, but feel free to add more Students!

Student alan = new Student("Alan", 11);

Student kevin = new Student("Kevin", 10);

Student annie = new Student("Annie", 12);

System.out.println(Student.printClassList());

System.out.println(Student.getLastStudent());

System.out.println(Student.getStudent(1));

Student.addStudent(2, new Student("Trevor", 12));

System.out.println(Student.printClassList());

System.out.println(Student.getClassSize());

}

}

/* Student.java */

import java.util.ArrayList;

public class Student

{

private String name;

private int grade;

//Implement classList here:

private static ArrayList<Student> classList = new ArrayList<Student>();

public Student(String name, int grade)

{

this.name = name;

this.grade = grade;

classList.add(this);

}

public String getName()

{

return this.name;

}

//Add the static methods here:

public static String printClassList()

{

String names = "";

for(Student name: classList)

{

names+= name.getName() + "\n";

}

return "Student Class List:\n" + names;

}  

public static String getLastStudent() {

// index run from 0 so last student will be size -1

return classList.get(classList.size()-1).getName();

}

public static String getStudent(int i) {

// array starts from 0 so i-1 will be the student

return classList.get(i-1).getName();

}

public static void addStudent(int i, Student student) {

// array starts from 0 so, we add at i-1 position

classList.add(i-1,student);

// remove extra student

classList.remove(classList.size()-1);

}  

public static int getClassSize() {

return classList.size();

}

}

You might be interested in
What is RAM? explain it
Zina [86]
RAM is memory in the computer
3 0
3 years ago
Read 2 more answers
A(n) ________ is a chart based on PivotTable data.
Mrrafil [7]
Well since it’s a chart based on a PivotTable prettyyyy sure it’s gonna be a PibltChart
7 0
2 years ago
Egovernment involves the use of strategies and technologies to transform government by improving the delivery of services and en
aleksandrvk [35]
I guess the answer True
3 0
3 years ago
Match the expenses to their respective categories.
satela [25.4K]
Lambo , vacation and lavish weddings in want the other two in needs
4 0
3 years ago
Read 2 more answers
Match the data-management concepts to their meanings.
harina [27]
Master data = represents critical data for important functions
Big data = represents a large volume of data for analysis
Outsourcing = uses another firms services
Archiving = stores rarely accessed important data
6 0
3 years ago
Other questions:
  • What are the 6 external parts of a computer system
    8·1 answer
  • Most programming languages provide loop statements that help users iteratively process code. In Coral you can write loops that h
    15·1 answer
  • Help Asap! Marking brainliest!✨
    15·2 answers
  • EDVAC stands for? on which theory it is made on?
    15·1 answer
  • Tree diagrams are useful for
    12·1 answer
  • An alteration threat violates information integrity. <br> a. True <br> b. False
    13·1 answer
  • Dominic's teacher asked him to create a chart or graph to compare the different grade levels in the school's FBLA club. Which ch
    5·2 answers
  • The memory used by the CPU to temporarily hold data while processing is called _______. random access memory central processing
    5·1 answer
  • The impact of the destruction of train station on the budget of the minister of finance
    5·1 answer
  • Since the size of cache is always smaller than the size of the main memory, the sum of bits of the offset and index of a cache w
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!