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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:47:14+00:00 2026-06-13T10:47:14+00:00

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

  • 0

Requirements

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 and can be accessed and modified by any subclass.

  • 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, ICalculator2, based on ICalculator. The class ICalculator2 has one additional method, negate, that receives no arguments. The effect of negate is to reverse the sign of currentValue. For example, if currentValue is zero, there is no change, if it is -22 then it becomes 22, if it is 100 it becomes -100. Furthermore negate returns the new value of currentValue.

Source Code

public class ICalculator2 extends ICalculator {
public int negate() { 
int val = add(0);      
if (val == -22) return val * -1;   
else if (val == 100) return val * -1;   
else return 0;}}

Remarks:

  • Your code had an error during execution

More Hints:

  • You might want to use a number other than 100

  • You might want to use a number other than 22

  • Are you sure you want to use: val

Hints:

  • You might want to use: <
  • Are you sure you want to use: =
  • 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-13T10:47:15+00:00Added an answer on June 13, 2026 at 10:47 am

    You didn’t need to do any of those strange calculations. Try this instead:

    public class ICalculator2 extends ICalculator {
        public int negate() { 
            return (currentValue = -currentValue);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

requirement Assume the availability of an existing class, ICalculator, that models an integer arithmetic
My requirements are that Ads have a definite size, could be different media types
Let's assume there is a SQL Server 2008 table like below, that holds 10
I need to store a large table (several millions or rows) that contains a
I'm looking for a persistent key value storage that supports consistency, availability and compare-and-set.
Can I assume that for any type T , the type std::list<T> will have
first I'd like to explain the situation/requirements that lead to the question: In our
I have a defined route that displays a dynamic page: page_show: url: /:domain_slug/:slug class:
I have a simple question that I assume does not have a simple solution.
Let's assume I am in charge of developing a Scrabble game, being that one

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.