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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:54+00:00 2026-05-26T15:23:54+00:00

private boolean isValid(int aRating) { return aRating >= 1 && aRating <= 10; }

  • 0
    private boolean isValid(int aRating)
{                     

  return aRating >= 1 && aRating <= 10;

}

                or

    private boolean isValid(int aRating)
{                     

  if (aRating >=1 && aRating <=100
      return true;
  else
      return false

}

I now need to Write a method setRating(aRating) that sets the rating to aRating IF it is valid. So i am assuming that i need to use the method above in a public method to check if it is valid. If it is valid i then need to set rating = to aRating. So far my idea has been this:

    public void setRating(int aRating)
{
   if (isValid() == true)
       rating = aRating;

}

But i cannot use isValid as a == to true because it is a method. i also try using isValid(); in order to just try and use the method but it wont allow because of the (int aRating) at the top. If i do not have the identifier it then wont allow me to use aRating at all…

Now that it is

public void setRating(int aRating)
     {
       if (isValid(aRating))
          rating = aRating;
     }

I need to make a setRating() method that allows the user to input something from the keyboard and again it has to be valid, i keep getting an error because it says i cant overload SetRating(int aRating) Twice, which i understand. But if i try to take the int part out it is invalid because it needs a parameter. this is what i have

    public void setRating()
{
    Scanner keyboard = new Scanner(System.in);
  if (isValid(aRating))
      rating = keyboard.nextInt();
}
  • 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-05-26T15:23:55+00:00Added an answer on May 26, 2026 at 3:23 pm
    public void setRating(int aRating)
    {
       if (isValidRating(aRating))
           this.rating = aRating;
    }
    

    This might not be required for your homework, but in the real world you may also want to consider throwing an IllegalArgumentException if validation fails.

    Example:

    public void setRating(int aRating)
    {
        if (isValidRating(aRating))
            this.rating = aRating;
        else 
            throw new IllegalArgumentException("Invalid rating.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So the exact wording is, Write a private method isValid(aRating) that returns true if
This isn't valid code: public class MyClass { private static boolean yesNo = false;
If I have a boolean field like: private static final boolean DEBUG = false;
Here is my JPA2 / Hibernate definition: @Column(nullable = false) private boolean enabled; In
public class BloodPressure { public Int16? Diastolic { get; set; } private Boolean IsValid
Consider the following block of code: class CheckStore { private String displayText; private boolean
I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
private string? typeOfContract { get { return (string?)ViewState[typeOfContract]; } set { ViewState[typeOfContract] = value;
private IEnumerable<string> Tables { get { yield return Foo; yield return Bar; } }

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.