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 738849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:19:59+00:00 2026-05-14T08:19:59+00:00

I need to know how I can insert data inside objects inside an array

  • 0

I need to know how I can insert data inside objects inside an array of objects using my already made Set methods.

i need to know how should i do it through user , i mean JOptionPane input dialog

student[] s = new student[5];

for (int i=1 ; i <= s.length ;i++) {
    s[i] = new student(i,"AAA","Ecommerce",0.0);
}

for (int i=1; i<=s.length;i++) {
    name = JOptionPane.showInputDialog("Please Write Name for student n " + i);
    major = JOptionPane.showInputDialog("Please Write Major for student n " + i);
    gpa = Double.parseDouble(JOptionPane.showInputDialog("Please Write GPA for student n " +i));

    s[i] = new student(i,name,major,gpa);  
}

I tried to do vars here that get data from user by JOptionPane, but it seems that i only use my already made constructor , not the Set methods.

I need to use the methods because it has some validation code inside it.

Any ideas?

  • 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-05-14T08:19:59+00:00Added an answer on May 14, 2026 at 8:19 am

    Don’t use values as constructor parameters.

    Use only implicit constructor that will allocate memory.
    As for set methods, write them like :

    public void setName(String name) { this.name = name; }
    

    In this set methods do your validation code. Your class needs to have private attiributes, which are exact same as your constructor parameters.

    Then change line s[i]=new student(i,name,major,gpa);
    with

    s[i] = new Student();
    s[i].setNumber(i);
    s[i].setName(name);
    s[i].setMajor(major);
    s[i].setGpa(gpa);
    

    I hope this is what you meant

    Edit :
    Or continue using constructors and do validaing with parameters BEFORE you make new instance of Student

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unsorted array of objects. I need to know how I can
I need to know can we add image in TextArea through StyleableTextField htmlText because
i need to know how can i connect telephone using php languages
I need to know how can I add data from the database without refreshing
I need to know how can I get every instruction's duration so I can
I created a Custom Tab Navigator and now I need to know how can
I need to know how I can replace the last s from a string
I need to know how i can make a string like hello to Hello
I need to know if any JSON implementations can handle sparse arrays to my
I just need to know if WCF is platform independent like Webservices? Can the

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.