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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:16:55+00:00 2026-06-09T18:16:55+00:00

As you’ll see, I’m fairly new to object oriented programming. I’m trying to teach

  • 0

As you’ll see, I’m fairly new to object oriented programming. I’m trying to teach myself, but am stuck on this and can’t figure out what to do.

I’m trying to write some code to layout a rectangular grid into rows and columns. Think “laying out small squares onto a large rectangle”. The user will input how many of the “small squares” they have. My goal is to map this integer into the best layout of rows and column.

The user can input any integer from 20 through 100. For each of the 81 different possible entries, I have determined the best way to layout these small squares in rows and columns. What I need to do now is to get these 81 different layouts into my program then identify and return the one that applies to the user’s input.

Since there are only 81 values and they range through consecutive integers, I think that an array is the best idea (rather than a map, hashmap, vector, etc.). Here’s what I have thus far. It’s a bit of a mess, but I think you’ll get the idea of what I’m trying to do. Can anyone help me? I can’t seem to return the row and column values that I need.

Thank you!

public static void getLayout (int numSquares) {

    int rows;
    int columns;        

    Layouts myLayout = new Layouts();

    rows = myLayout[numSquares].r; //this is where it fails
    columns = myLayout[numSquares].c;
}

class RowCol<R, C> {

    /* Class Variables */
    public final R r;
    public final C c;

    public RowCol(R r, C c) {
        this.r = r;
        this.c = c;
    }

    public R getRow() {return r;}
    public C getCol() {return c;}
}

class Layouts {

    RowCol[] myLayouts;

    public Layouts() {

        /* Set the numbers of Rows and Columns for each possible
         * number of squares requested.
         */
            myLayouts[20] = new RowCol(5, 4);   // 20 Problems
            myLayouts[21] = new RowCol(7, 3);   // 21 Problems
            myLayouts[22] = new RowCol(5, 4);   // 22 Problems
            myLayouts[23] = new RowCol(5, 4);   // 23 Problems
            myLayouts[24] = new RowCol(6, 4);   // 24 Problems
            myLayouts[25] = new RowCol(5, 5);   // 25 Problems
            myLayouts[26] = new RowCol(6, 4);   // 26 Problems
            myLayouts[27] = new RowCol(6, 4);   // 27 Problems
            myLayouts[28] = new RowCol(7, 4);   // 28 Problems
            //etc...

Edit: Applying the responses below, I needed to intantiate an object in the Layouts class, which I did. Then, I modified the getLayout class to isolate the returned RowCol value. Here is that class updated. My issue at this point is that I can’t convert the row and column into integers so that I can use them as such.

public static void getLayout(int numSquares) {

    Layouts myLayout = new Layouts();
    RowCol myRC = myLayout.getLayout(numProbs);
    int rows = Integer.parseInt(myRC.getRow());
    int cols = Integer.parseInt(myRC.getCol());
}

The error is:

no suitable method found for parseInt(Object)
method Integer.parseInt(String) is not applicable
(actual argument Object cannot be converted to String by method invocation conversion)
method Integer.parseInt(String,int) is not applicable
(actual and formal argument lists differ in length)

EDIT: Solved. Thanks everybody!

  • 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-09T18:16:57+00:00Added an answer on June 9, 2026 at 6:16 pm

    Did you initialize your array?

    RowCol[] myLayouts = new RowCol[81];
    

    If you don’t initialize the array then the myLayouts reference is null and you’ll get a NullPointerException when you try to assign to or read from any of the indices.

    Update:

    The problem you’re experiencing with parseInt is stemming from the fact that you’re using raw-typed generics in your array. You have type parameters in the declaration of the RowCol class (class RowCol<R, C> has type parameters R and C), but you’re not specifying types when you declare instances of RowCol, so they’re just defaulting to the raw type which assumes everything is an Object. This should fix it:

    @SuppressWarnings("unchecked")
    RowCol<Integer,Integer>[] myLayouts = new RowCol[81];
    // . . .
    myLayouts[20] = new RowCol<Integer,Integer>(5, 4);   // 20 Problems
    myLayouts[21] = new RowCol<Integer,Integer>(7, 3);   // 21 Problems
    // . . .
    

    The above will generate a warning due to limitations Java puts on generics and arrays, but the @SuppressWarnings annotation should take care of it. You could also avoid this problem altogether by using an ArrayList (which has full generic support) instead of an Array.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has

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.