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]
4 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]4 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
Which of the following indicates what a reply to all function does in most email programs
vichka [17]
2 because reply to all only goes to the people in the group
6 0
3 years ago
I think it is a or c is it right?
LUCKY_DIMON [66]
C
She is emailing her boss that something is wrong.
4 0
3 years ago
Ben Dover is the name of my best immature joke thank you
OleMash [197]

Answer:Brilliant mine is gabe itch

Explanation:

4 0
3 years ago
Read 2 more answers
Pam wants to include a video from a website in an upcoming presentation. However, she knows she will not have access to an inter
Dima020 [189]
I think Download and save is the answer
3 0
3 years ago
Read 2 more answers
a) consider the binary number 11010010. what is the base-4 representation of (11010010)2? (there is a way to do this without con
loris [4]

The place value can be used to convert a binary number, such as 11010010, into decimal form: 11010010 = 1 x 27 + 1 x 26 + 0 x 25 +1 x 24.In light of the aforementioned, the base-4 number system has 4 digits: 0, 1, 2, and 3. Any 2-bit number can be represented by a single base-4 integer since a 2-bit number can only represent one of the values 0, 1, 2, or 3.

<h3>What does base 4 mean?</h3>
  • Base-4 is a quaternary  number system. Any real number is represented by the digits 0, 1, 2, and 3.
  • In light of the aforementioned, the base-4 number system has 4 digits: 0, 1, 2, and 3. Any 2-bit number can be represented by a single base-4 integer since a 2-bit number can only represent one of the values 0, 1, 2, or 3.
  • The four digits of Quaternary (Base 4) are 0 through 3.
  • Binary code 4 is 100. In a binary number system, we only use the digits 0 and 1 to represent a number, as opposed to the decimal number system, which uses the digits 0 to 9. (bits).

To learn more about Quarternary number system refer to:

brainly.com/question/28424526

#SPJ4

7 0
1 year ago
Other questions:
  • In the 1950s, the three major networks (ABC, NBC, and CBS) developed prime-time shows that would appeal to a general family audi
    11·1 answer
  • Radio waves pros and cons
    10·2 answers
  • Reasons for the growth of decision-making systems include:
    13·1 answer
  • Linux is a kind of software whose code is provided for use, modification, and redistribution. what kind of software is this?
    5·1 answer
  • Will mark brainliest
    14·1 answer
  • MODS ONLY answer this, I have something for you. I'm reporting this to make it easier
    14·1 answer
  • For what three media types can Photoshop optimize images? ​
    10·1 answer
  • Name:
    13·1 answer
  • The choice of database does not have any impact on the relevancy of search results?
    13·1 answer
  • Please help me on this it’s due now
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!