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

The Archive Base Latest Questions

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

I have items in a list which can have a severity level ( those

  • 0

I have items in a list which can have a severity level ( those levels are: info,warning,error,delay,…)

I want to program this in a OOP way so that I can add more severity levels easily if needed.
It’s been a while since I have used Java so I’m not sure how to do it the right way.

What I have is:

    Public class ListItem
    {
       int sev; 
       String name;
       public ListItem(String name, int s)
       {
          this.name = name; this.sev = s;
       }
       ...
    }

A severity should have an integer (like ‘1’) and just a name (like ‘information’)

I’d like to ‘predefine’ severities like:

public static final int WARNING = 1;
public static final int ERROR = 2;

But then, how can I display the name ‘WARNING’ when ‘1’ is given as severity to list item?
Am I having the best approach?

Thanks,

  • 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-09T04:55:01+00:00Added an answer on June 9, 2026 at 4:55 am

    You should use an enum instead of constants:

    enum Level {
       INFO, WARNING, ERROR;
    }
    

    You can print the Level using toString()

    Level level = Level.INFO;
    System.out.println(level.toString());
    

    prints

    INFO
    

    Changing to ListItem(String name, Level level) has the advantage of preventing you from creating a ListItem with an int value that isn’t defined as a valid level.

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

Sidebar

Related Questions

I have a list which has repeating items and I want a list of
Rails newbie here. I have a list of items which can have a status
I have a List container which can potentially have up to 100,000 items in
I have a UI with a Combo box. The list of items, which can
I have a view that has a list of items (which can be added
I have a list which is dynamically built, but there are empty list items
I have a list which contains some items of type string. List<string> lstOriginal; I
I have a method which is list my items from a server. Therefore, this
I have a list of items ('sections') which has a getter and a setter.
I have a list of items of type ViewLookupItem which has these properties: For

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.