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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:11:44+00:00 2026-06-01T00:11:44+00:00

I’m working on homework and I’m close but I am having an issue. I

  • 0

I’m working on homework and I’m close but I am having an issue. I just learned how to work with packages in eclipse so I have a class that is importing another class from a package (I think I said that right)
The main prompts the user to enter an integer between -100 and 100 and I am having an issue with validating it. I know the issue is where I’m importing I’m just unsure the direction I need to go to fix it.

This is a section of my main code. (my issue starts with the last couple lines if you want to skip ahead)

    import myUtils.util.Console;

    public class ConsoleTestApp
    {
         public static void main(String args[])
         {
             // create the Console object
             Console c = new Console();

            // display a welcome message
            c.println("Welcome to the Console Tester application");
            c.println();

            // int
            c.println("Int Test");
            int i = c.getIntWithinRange("Enter an integer between -100 and 100: ", -101, 101);
            c.println();

In that last line of code

    int i = c.

I get a squiggly line under i that tells me I am not using the local variable so I’m not sure what exactly fixes that in this situation since I’m trying to use it in another class. Do I need to create an object?

I have a class called Console that is located in another package that I believe I have properly imported.
here is the code I am stuck on in my console class.

package myUtils.util;

import java.util.Scanner;

public class Console 

{
Scanner sc = new Scanner(System.in);
public void print(String s)
{
    System.out.println();
}

public void println(String s)
{
    System.out.println();

}

public void println()
{
    System.out.println();

}

public int getIntWithinRange(String prompt, int min, int max)
{

    int i = 0;
    boolean isValid = false;
    while (isValid == false)
    {
        System.out.println(prompt);
        if (sc.hasNextInt())
        {

            i = sc.nextInt();
                if (i < min)
                {
                    System.out.println("Error! Please enter an integer greater than -100");
                }

                else if (i > max)
                {
                    System.out.println("Error! Please enter an integer less than 100");
                }

                else
                    isValid = true;
        }

        else 
        System.out.println("Error! Invalid number value");
        sc.nextLine();

    }
        // return the int
        return i;

}

public double getDoubleWithinRange(String prompt, double min, double max)
{

    int d = 0 ;
    boolean isValid = false;
    while (isValid == false)
    {
        System.out.println(prompt);
        if (sc.hasNextInt())
        {
            //if user chooses menu option less than 1 the program will print an error message
            d = sc.nextInt();
                if (d < min)
                {
                    System.out.println("Error! Please select menu option 1, 2, or 3");
                }
                //if the user chooses a menu option greater than 3 the program will print an error
                else if (d > max)
                {
                    System.out.println("Error! Please select menu option 1, 2, or 3");
                }
                //if the option is between 1 and 3 the menu option is valid
                else
                    isValid = true;
        }

        else 
        System.out.println("Error! Invalid number value");
        sc.nextLine();

    }
        // return the int
        return d;

}


public String getRequiredString(String prompt)
{
    return prompt;

}

public String getChoiceString(String prompt, String s1, String s2)
{
    return s2;

}

public int getInt(String prompt)
{
    return 0;

}

}

when I run this I keep getting my last print which is an invalid number value. am I not importing the code from the main method in the other console properly?

  • 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-01T00:11:45+00:00Added an answer on June 1, 2026 at 12:11 am

    This isn’t an import problem. If you’re importing something wrong, your program won’t compile in the first place, or at a bare minimum won’t launch.

    As far as actually fixing your problem, I’d recommend looking at the two lines you think are associated with the outermost else in getIntWithinRange and considering which code is actually associated with the else and which code isn’t. The main issue is that an if or an else is only associated with one line unless you surround the multiple lines with curly braces. So, you should modify the last else of getIntWithinRange to look like

    else {
        System.out.println("Error! Invalid number value");
        sc.nextLine();
    }
    

    EDIT: In response to the updated question

    I get a squiggly line under i that tells me I am not using the local variable so I’m not sure what exactly fixes that in this situation since I’m trying to use it in another class. Do I need to create an object?

    Right now, the code that you have written doesn’t use i in main. That includes not passing it to any other method or to any constructor. Since i is a local variable, it’s not accessible outside main, so Eclipse warns you. This “squiggly red line” warning from Eclipse won’t stop your code from compiling and running just fine, but it is intended to help you find bugs in your own code.

    On a broader note, there are a lot of bugs that arise because of unused locals, and Eclipse wants to help you prevent those bugs. Consider the example of wanting to initialize all the elements of a two-dimensional array to some user-supplied number (the variable names are shorter than I would use in a real program, but they still get the point across):

    public static final int N = 10;
    
    public void main(String[] args) {
        int[][] a = new int[N][N];
        int n = /* Read number from the user */;
    
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                a[i][j] = i; // Bug - we meant to initialize to n
            }
        }
    
        // ...
    }
    

    Eclipse’s flagging of unused locals helps you find these kinds of bugs more easily.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what 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.