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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:52:51+00:00 2026-06-15T03:52:51+00:00

I’ve just approached to the Java language, so I usually get even into banal

  • 0

I’ve just approached to the Java language, so I usually get even into banal errors. The following should be one of them.
Es1.java:93: error: variable f might not have been initialized
Things to know before looking into the code – I’m using some custom class: ConsoleInputManager and ConsoleOutputManager work substantially like Scanner and System.out; Figure is an abstract class; Circle, Square and Rectangle extend Figure

import prog.io.*;
//ConsoleInputManager, ConsoleOutputManager
import prog.utili.*;
//Figure, Circle, Squade, Rectangle
class Es1{
public static void main(String[] args){

//Variables
ConsoleInputManager in = new ConsoleInputManager();
ConsoleOutputManager out = new ConsoleOutputManager();
int com1,com2,com3;
com1 = com2 = com3 = 0;
double r,s,l,w;
r = s = l = w = 0.0;
Figure f;

do{
    //Menu
    out.println("1. Insert a new figure");
    out.println("2. Calculate the area of the current figure");
    out.println("3. Examine the current figure");
    out.println("4. Exit the program\n");

    //Input
    com1 = in.readInt("Command: ");

    //New figure
    if (com1 == 1){
        do{
            out.println("1. Circle");
            out.println("2. Square");
            out.println("3. Rectangle");
            out.println("4. Back to main menu\n");
            com2 = in.readInt("Command: ");
            //Circle
            if (com2 == 1){
                s = l = w = 0.0;
                do{
                    r = in.readDouble("Radius: ");
                } while (r <= 0);
            }
            else
            //Square
            if (com2 == 2){
                r = l = w = 0.0;
                do{
                    s = in.readDouble("Side: ");
                } while (s <= 0);
            }
            else
            //Rectangle
            if (com2 == 3){
                r = s = 0.0;
                do{
                    l = in.readDouble("Length: ");
                } while (l <= 0);
                do{
                    w = in.readDouble("Width: ");
                } while (w <= 0);
            }
        } while (com2 != 4);
    }
    else

    //Area
    if (com1 == 2){
        if (r != 0.0){
            f = new Circle(r);
            out.println("Area = " + f.getArea());
        }
        else
        if (l != 0.0){
            f = new Square(s);
            out.println("Area = " + f.getArea());
        }
        else
        if ( b != 0.0){
            f = new Rectangle(l,w);
            out.println("Area = " + f.getArea());
        }
        else
            out.println("It hasn't been inserted any figure");
    }
    else

    //Examination
    if (com1 == 3){
        do{
            out.println("1. Examine the current figure");
            out.println("2. Back to main menu");
            com3 = in.readInt("Command: ");
            if (com3 == 1){
                if (f instanceof Circle)
                    out.println("Circle");
                else
                if (f instanceof Square)
                    out.println("Square");
                else
                if (f instanceof Rectangle)
                    out.println("Rectangle");
                else
                    out.println("It hasn't been inserted any figure");
            }   
        } while (com3 != 2);
    }

} while (com1 != 4);
}
}
  • 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-15T03:52:53+00:00Added an answer on June 15, 2026 at 3:52 am
    Figure f;
    

    Above statement is inside main method. There is a possibility that if/else conditions not satisfied, which leaves f unassigned.

    Change it to something like below:

    Figure f=null;
    

    All local variables need to have some value assigned before being used.

    Along with that, make sure to perform null check before performing any operations on f.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
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 reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.