Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:38:43+00:00 2026-06-04T08:38:43+00:00

For this i am running BlueJ doing object-oriented java and i have JVM 7.1

  • 0

For this i am running BlueJ doing object-oriented java and i have JVM 7.1 active….

Ok so i have to make an application for my degree and im having trouble. I am thankful the “teacher” has let me use my tri-array system since the iterator messed up my single-array system.

Regrettably, i was unable to find anything on the internet to help with my issue…

Basically when i go to add a “Student” to the array, the object is null in all fields. and i cannot figure out how to modify them.

My arrays use the diamond notation. Similar to the following:

private ArrayList<Student> students;

this is the form of array i am currently using and there are 2 more arrays.

private ArrayList<CollegeEmployee> staff;
private ArrayList<Faculty> members;

I was advised to use a single array but as said, the iterator messed it up and as long as i can fix it, i dont care how many arrays i have lol.

The program runs within a while loop and prompts the user to enter a letter for a certain command. when the user enters “s” a student is then added to the array and this is where the problem comes in. the object is given null values and i have no clue how to modify them…the following is the method that calls the object constructor

private void addStudent()
{
    Student b = new Student(firstName, lastName, address, postCode, phoneNumber, gradePointAvg, selectedCourse);
students.add(b);
}

When the array is printed as the user quits the program, i get the following input from the terminal window:

null, null, null, 0, 0
0
null

My question is: how do i give object b values to override the null ones. Btw the values must be entered by the user and not pre-set in the declaration of the array.

Thank you for your time 🙂

This stuff makes me hate code xD

EDIT:

Here is the constructor and fields from the student class:

    private String title;
        public double gradePointAvg;
        public String selectedCourse;

        /**
         * Constructor for objects of class Student
         */
        public Student(String firstName, String lastName, String address, int postCode, int phoneNumber, double gradePointAvg, String selectedCourse)
        {
            super(firstName, lastName, address, postCode, phoneNumber);
            this.title = title;
            this.gradePointAvg = gradePointAvg;
            this.selectedCourse = selectedCourse;
        }

Person superclass constructor:

public String firstName;
public String lastName;
public String address;
public int postCode;
public int phoneNumber;

 /**
 * Constructor for objects of class Person
 */
public Person(String firstName, String lastName, String address, int postCode, int phoneNumber)
{
    // initialise fields
    this.firstName = firstName;
    this.lastName = lastName;
    this.address = address;
    this.postCode = postCode;
    this.phoneNumber = phoneNumber;
}

The method above, addStudent calls the student constructor which then calls the person constructor. Yes it does have to be like this as its the restrictions of the project.

And i made my fields public for now since they were set as protected because private is local scope.

Thank you guys so much for checking my code out..i wish my teacher was better >.<

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:38:45+00:00Added an answer on June 4, 2026 at 8:38 am

    In your Student class firstName, lastName, address,selectedCourse are presumably String and Java will initialize instance variables which are Objects (String in your case) to null, for your other fields namely postCode, phoneNumber which I think are int default value is 0.

    When you are in addStudent method check the values that you are using to construct the object, it seems all Strings are null and int are not initialized.

    Student b = new Student(firstName, lastName, address, postCode, phoneNumber, gradePointAvg, selectedCourse);
    

    When above code is executed I think none of the parameters like firstName, lastName e.t.c have any value, thats why it is showing you null.

    Before you add new Student object to your list students, prompt your user to give values for firstName, lastName, address e.t.c, then use those values to construct your Student object.

    Update Sample Code:

    Student Class:

    package com.mumz.test.scanner;
    
    public class Student {
        private String firstName = null;
        private String lastName = null;
        /**
         * @param firstName
         * @param lastName
         */
        public Student(String firstName, String lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }
        /**
         * @return the firstName
         */
        public String getFirstName() {
            return firstName;
        }
        /**
         * @param firstName the firstName to set
         */
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        /**
         * @return the lastName
         */
        public String getLastName() {
            return lastName;
        }
        /**
         * @param lastName the lastName to set
         */
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return String.format("Student [firstName=%s, lastName=%s]", firstName, lastName);
        }
    }
    

    The main class

    package com.mumz.test.scanner;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class StudentScannerApp {
        private List<Student> students = new ArrayList<Student>();
        public static void main(String[] args) {
    
            StudentScannerApp studentScannerApp = new StudentScannerApp();
            //This scanner we will use for reading data from input stream
            Scanner inputStream = new Scanner(System.in);
    
            System.out.println("Enter First Name");
            String firstName = inputStream.nextLine();
            System.out.println("Enter Last Name");
            String lastName = inputStream.nextLine();
            studentScannerApp.addStudent(firstName, lastName);
    
            System.out.println("Enter Another student details");
            System.out.println("Enter First Name");
            firstName = inputStream.nextLine();
            System.out.println("Enter Last Name");
            lastName = inputStream.nextLine();
            studentScannerApp.addStudent(firstName, lastName);
    
            System.out.println(studentScannerApp.students);
        }
    
        private void addStudent(String firstName, String lastName){
            Student student = new Student(firstName, lastName);
            students.add(student);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this running software that is currently being used by about 400 people.
Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence
I have this code running in CentOS 5.5 ,PHP 5.1.6 ,Apache/2.2.3 ,ImageMagick 6.2.8 $convert
We have a .NET application running in production for over a year. It is
I'm trying to get this running: JAXB interface But I always get the error
Try running this in a .VBS file MsgBox(545.14-544.94) You get a neat little answer
In running this on index.html, I get the following error: Uncaught SyntaxError: Unexpected token
When running this powershell command Get-ChildItem -Recurse -Include *.txt You get multiple tables in
I'm running this SELECT statement: TIMEDIFF(NOW(), posts.date_modified) as time_ago And getting results in the
I'm running this code on my datasheet subform when my form loads and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.