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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:29:58+00:00 2026-06-17T12:29:58+00:00

my issue is in my NumberAnalyzer.java class, I’m supposed to be able to use

  • 0

my issue is in my “NumberAnalyzer.java” class, I’m supposed to be able to use the “Number.java” class to determine if a number from the ArrayList is odd (as well as even and perfect later on) but since the “isOdd()” method in “Number.java” doesn’t read in an int or other variable itself, I can’t find a way to test each number to make “oddCount” in the “countOdds” method of “NumberAnalyzer.java” increase to produce the number of odd numbers in the string from the runner class.

NumberAnalyzer.java

import java.util.ArrayList;
import java.util.Scanner;

import com.sun.xml.internal.ws.api.pipe.NextAction;

import static java.lang.System.*;

public class NumberAnalyzer
{
private ArrayList<Number> list;

public NumberAnalyzer()
{

}

public NumberAnalyzer(String numbers)
{
    list = new ArrayList<Number>();
    String nums = numbers;
    Scanner chopper = new Scanner(nums);
    while(chopper.hasNext()){
        int num = chopper.nextInt();
        list.add(new Number(num));
    }
    chopper.close();
    System.out.println(list);
}

public void setList(String numbers)
{
    list = new ArrayList<Number>();
    String nums = numbers;
    Scanner chopper = new Scanner(nums);
    while(chopper.hasNext()){
        int num = chopper.nextInt();
        list.add(new Number(num));
    }
    chopper.close();

}

public int countOdds()
{
  int oddCount=0;
  for(int i = 0; i < list.size(); i++){
      if(Number.isOdd()== true){
          oddCount++;
      }
  }
  return oddCount;
}

public int countEvens()
{
  int evenCount=0;



  return evenCount;
}

public int countPerfects()
{
    int perfectCount=0;



  return perfectCount;
}

public String toString( )
{
    return "";
}
}

Number.java

public class Number
{
private Integer number;

public Number()
{


}

public Number(int num)
{
    number = num;
}

public void setNumber(int num)
{
    number = num;
}

public int getNumber()
{
    return number;
}   

public boolean isOdd()
{
    if(number%2==0){
        return false;
    }
    return true;
}

public boolean isPerfect()
{
    int total=0;
    for(int i = 1; i < number; i++){
        if(number%i==0){
            total+= i;
        }
    }


    return (number==total);
}   

public String toString( )
{
    String output = getNumber() + "\n" + getNumber()+ "isOdd == " + isOdd() + "\n" + getNumber()+ "isPerfect==" + isPerfect()+ "\n\n";
    return output;
}
}

runner class

import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.System.*;

public class Lab16b
{
public static void main( String args[] )
{
    NumberAnalyzer test = new NumberAnalyzer("5 12 9 6 1 4 8 6");
    out.println(test);
    out.println("odd count = "+test.countOdds());
    out.println("even count = "+test.countEvens());
    out.println("perfect count = "+test.countPerfects()+"\n\n\n");


    //add more test cases


}
}
  • 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-17T12:29:59+00:00Added an answer on June 17, 2026 at 12:29 pm

    When you call

    test.countOdds());
    

    control goes to NumberAnalyzer.java

    public int countOdds()
    {
      int oddCount=0;
      for(int i = 0; i < list.size(); i++){
          if(Number.isOdd()== true){
              oddCount++;
          }
      }
      return oddCount;
    }
    

    And here you are calling Number.isOdd() method by Class name as a static way but i do not think you can do this way because isOdd() is not static.

    It is compile time error

    Solution:

    Iterate your list and send value one by one from the list to isOdd(int val) method.

    Try to make isOdd() method static which accept one numeric parameter and will return true or false.

    increase your counter based on return type as you do.

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

Sidebar

Related Questions

Issue: Each li tag not coming one by one (fixed from top left). Instead
Issue I want to implement TransparencyChecker Interface which would verify that from any exchange
Issue Seems like the condition gets ignored. Here is my scenario: Source class public
Issue I'm getting no output from a simple cout, whereas a printf will always
Issue: When creating a new SilverLight Application Project from Visual Studio 2010, the SilverLight
Issue : I have Json coming back from the server. The Json is an
Issue: Issue is due to "ValidatorCalloutExtender" which fires even when the RequiredFieldValidator is disabled
Issue: Solved, I was able to produce a script that will go through my
ISSUE I am trying to convert a 8 digit number into a date while
Issue: The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able

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.