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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:21:32+00:00 2026-06-13T13:21:32+00:00

requirement Assume the availability of an existing class, ICalculator, that models an integer arithmetic

  • 0

requirement

Assume the availability of an existing class, ICalculator, that models an integer arithmetic calculator and contains:

  • an instance variable currentValue that stores the current int value
    of the calculator

  • methods add, sub, mul, and div

    Each method in ICalculator receives an int argument and applies its operation to currentValue and returns the new value of currentValue. So, if currentValue has the value 8 and sub(6) is invoked then currentValue ends up with the value 2, and 2 is returned.

So, you are to write the definition of a subclass, ICalculator1, based on ICalculator. The class ICalculator1 has one additional method, sign, that receives no arguments, and doesn’t modify currentValue. Instead, it simply returns 1, 0 or -1 depending on the whether currentValue is positive, zero, or negative respectively.

code:

1 public class ICalculator1 extends ICalculator {
2 public int getCurrentValue() {return currentValue;} //**did not need this line**
3 
4 int sign() {
5 if(currentValue > -1) return 0; //changed to**int val = add(0);**
6 else if(currentValue < 0) return -1; //changed to **if (val > 0) return 1;**
7 else return 1; //changed to **else if (val < 0) return -1;**
8 }}

error message:

ICalculator1.java:2: error: currentValue has private access in ICalculator
public int getCurrentValue() {return currentValue;}
                                     ^
ICalculator1.java:5: error: currentValue has private access in ICalculator
if(currentValue > -1) return 0;
   ^
ICalculator1.java:6: error: currentValue has private access in ICalculator
else if(currentValue < 0) return -1;
        ^
3 errors

Not sure what I’m doing wrong?

  • 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-13T13:21:33+00:00Added an answer on June 13, 2026 at 1:21 pm

    So it seams that currentValue is private and thus cannot be accessed directly inside your subclass. Since your methods actually return the value of currentValue, you can exploit this inside your subclass, like this for example :

    public int sign() {
       int val = add(0);   // add 0 and return currentValue
       if (val > 0) return 1;
       else if (val < 0) return -1;
       else return 0;
    }
    

    As others have suggested, if you can modify the visibility of currentValue, make it protected and you won’t need that add(0) hack. However if you cannot modify ICalculator, this is one possibility.

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

Sidebar

Related Questions

Requirements Assume the availability of an existing class, ICalculator, that models an integer arithmetic
Requirement : Should update MySQL database with that of MS Sql Server updates which
Assume that the following code is being executed by 10 threads. pthread_mutex_lock(&lock) Some trivial
I have a requirement to build an application that a company can use to
Suppose I have a custom collection class that provides some internal thread synchronization. For
Assume I have a class implementing two or more COM interfaces: class CMyClass :
Assume that I need to manage an artifact that consists of an aribtrary folder
Let's assume we have a class Student with the following constructor: /** Initializes a
I am writing a standard database-backed business application. Assume that I work with bank
I've a requirement in which I have a start and End time. For instance

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.