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
In 2009 to 2010, how many social network users were reported as being victims of online abuse?
Dafna1 [17]
The answer is B because being victims of online abuse is not important
7 0
3 years ago
Read 2 more answers
How can you get in touch with someone when they ain't answering you ☹
mixer [17]
You can go to their house and talk to them
3 0
3 years ago
If you would like to give another user permissions on your mailbox or to particular folders within your mailbox, which role shou
Darya [45]

Answer:

Delegate

Explanation:

8 0
3 years ago
What are the benefits of transferable skills check all the boxes that apply
Nonamiya [84]

Answer:

They allow easy cross-company transfers.

They help a person develop self-esteem.

They open up a variety of employment options.

Explanation:

7 0
3 years ago
Read 2 more answers
Which internet resource can you use to publicly describe an adventure trip you recently made?
Hitman42 [59]
Itd Be Blog! Hope This Help Mate:)
7 0
2 years ago
Read 2 more answers
Other questions:
  • I need a idea of a origami for my coding class and it needs to be easy to make
    15·2 answers
  • Explain why living things store energy in lipids instead of in carbohydrates
    5·1 answer
  • A(n ____ is anything about which data are to be collected and stored.
    8·1 answer
  • Sulfur content is measured in
    11·1 answer
  • The default (preset slide layouts are set up in ____ orientation.
    15·1 answer
  • Phil wants to make a dark themed superhero movie. What could be his target demographic
    11·2 answers
  • What are the different types of application architecture
    5·1 answer
  • Cathy designed a website for a cereal brand. When users view the website, their eyes first fall on the brand name, then they vie
    14·1 answer
  • Which of the following shows data conversion taking place?
    12·1 answer
  • What would a good digital citizen do if he sees his classmate left her email account open on a school computer by mistake?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!