Note that there are some explanatory texts on larger screens.

plurals
  1. POArray setting length and storing information
    primarykey
    data
    text
    <p>This is homework. I'm trying to work with arrays and this is the first project working with them. My book shows all kinds of examples but the way they code the examples doesn't do any justice to what the assignment calls for.</p> <p>I am trying to write a program that asks a user to enter students into the system. The program first asks how many you will enter then it will prompt you for the first name, last name, and score.</p> <p>What I am trying to accomplish with this section of code is to ask the user how many students they will enter. The line of code that says </p> <pre><code> getStudentCount(); </code></pre> <p>is a method that collects that information and then returns studentCount</p> <p>I tried to code this to where the length of the array is going to be the number the user enters but it's not working so I wanted to ask for guidance. Ideally if this works and the user enters 3 then you will be prompted to enter the information 3 times. If the user enters 0 then the program doesn't ask you anything.</p> <pre><code> public static void main(String[] args) { System.out.println("Welcome to the Student Scores Application."); int studentCount = 1; getStudentCount(); studentCount = sc.nextInt(); String [] students = new String[studentCount]; for (int i = 0; i &lt; students.length; i++) { Student s = new Student(); String firstName = getString("Enter first name: "); s.setFirstName(firstName); String lastName = getString("Enter last name: "); s.setLastName(lastName); int score = getScore("Enter score: "); s.setScore(score); } } </code></pre> <p>Everything I had in the program worked up until I tried to code</p> <pre><code> String [] students = new String[studentCount]; for (int i = 0; i &lt; students.length; i++) </code></pre> <p>which tells me there is something wrong with the way I am doing this.</p> <p>Also the assignment asks that I store the information in the array. I'm not clear on how to call it or I guess store it.... I have another class with setters and getters. Is that enough to store it? How would I call it? Again this is homework so any guidance is appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload