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

  • Home
  • SEARCH
  • 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 6975889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:25:37+00:00 2026-05-27T17:25:37+00:00

I have a year object. For now lets say only two years and its

  • 0

I have a year object. For now lets say only two years and its getters and setters

private String mYearOne;
private String mYearTwo;
public String getmYearOne() {
    return mYearOne;    }
public void setmYearOne(String mYearOne) {
    this.mYearOne = mYearOne;   }
public String getmYearTwo() {
    return mYearTwo;    }
public void setmYearTwo(String mYearTwo) {
    this.mYearTwo = mYearTwo;   }

Then each year has three insurance plans. And its getters and setters.

private String healthPlan;
private String carPlan;
private String housePlan;
private String healthPlanTwo;
private String carPlanTwo;
private String housePlanTwo;
public String getHealthPlan() {
    return healthPlan;  }
public void setHealthPlan(String healthPlan) {
    this.healthPlan = healthPlan;   }
public String getCarPlan() {
    return carPlan; }
public void setCarPlan(String carPlan) {
    this.carPlan = carPlan; }
public String getHousePlan() {
    return housePlan;   }
public void setHousePlan(String housePlan) {
    this.housePlan = housePlan; }
public String getHealthPlan() {  //For the second year
    return healthPlan;  }
public void setHealthPlan(String healthPlan) {
    this.healthPlan = healthPlan;   }
public String getCarPlan() {
    return carPlan; }
public void setCarPlan(String carPlan) {
    this.carPlan = carPlan; }
public String getHousePlan() {
    return housePlan;   }
public void setHousePlan(String housePlan) {
    this.housePlan = housePlan; }
public String getHealthPlanTwo() {
    return healthPlanTwo;   }
public void setHealthPlanTwo(String healthPlanTwo) {
    this.healthPlanTwo = healthPlanTwo; }
public String getCarPlanTwo() {
    return carPlanTwo;  }
public void setCarPlanTwo(String carPlanTwo) {
    this.carPlanTwo = carPlanTwo;   }
public String getHousePlanTwo() {
    return housePlanTwo;    }
public void setHousePlanTwo(String housePlanTwo) {
    this.housePlanTwo = housePlanTwo;   }

You will notice the code is bulky. I need to define them in a <list> of year. So that if 10 years are considered, I would have 10 multiplied
by 3 = 30 plans and its getters and setters respectively.

How could this be done?

  • 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-27T17:25:37+00:00Added an answer on May 27, 2026 at 5:25 pm

    I think your best bet will be to maintain a count of number of years and arraylists for the insurance plans. This way, you can get the arraylist once and get the insurance plan details for whatever year you actually want. This will be characterized by a single insurance plan arraylist and a single arraylist for years.

    private ArrayList mYear;
    private ArrayList healthPlan;
    private ArrayList carPlan;
    private ArrayList housePlan;
    
    public String getHousePlanForYear(String year){
    return housePlan.get(mYear.indexOf(year));
    }
    
    public void setHousePlanForYear(String housePlan, String year){
    this.housePlan.set(mYear.indexOf(year), housePlan);
    }
    
    

    Similarly for the other plans. Of course, all this is assuming that the year is always present and other boundary conditions. Just add your boundary checks in these getters and setters and you will be good to go. 🙂

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

Sidebar

Related Questions

I have a object with 3 variable (id(string), year(int), pay(double)) I have created an
Within the last year I have become addicted to subversion. I am an only
I have been writing in PHP for just over half a year now, and
I have been using StructureMap for more than a year now. And all this
I have the following code: Private Sub btnReserve_Click(ByVal sender As Object, ByVal e As
So I've been learning C# for like a year now (I'm 20 years old)
I have a string like this: 250920111414 I want to create a DateTime object
I have this question on and of for a year or two, but it
I've been programming a lot in standard C for about a two years now.
I have a year 2009, a month 11 and a day 12. All of

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.