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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:43:38+00:00 2026-05-28T03:43:38+00:00

class Point { BigDecimal x; BigDecimal y; Point(double px, double py) { x =

  • 0
class Point {

  BigDecimal x;
  BigDecimal y;

  Point(double px, double py) {
    x = new BigDecimal(px);
    y = new BigDecimal(py);
  }

  void addFiveToCoordinate(String what) {
    if (what.equals("x")) {
      BigDecimal z = new BigDecimal(5);
      x.add(z);
    }
  }

  void show() {
    System.out.print("\nx: " + getX() + "\ny: " + getY());
  }

  public BigDecimal getX() {
    return x;
  }

  public BigDecimal getY() {
    return y;
  }

  public static void main(String[] args) {
    Point p = new Point(1.0, 1.0);
    p.addFiveToCoordinate("x");
    p.show();
  }
}

Ok, I would like to add 2 BigDecimal values. I’m using constructor with doubles(cause I think that it’s possible – there is a option in documentation). If I use it in main class, I get this:

x: 1
y: 1

When I use System.out.print to show my z variable i get this:

z: 5
  • 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-28T03:43:38+00:00Added an answer on May 28, 2026 at 3:43 am

    BigDecimal is immutable. Every operation returns a new instance containing the result of the operation:

     BigDecimal sum = x.add(y);
    

    If you want x to change, you thus have to do

    x = x.add(y);
    

    Reading the javadoc really helps understanding how a class and its methods work.

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

Sidebar

Related Questions

I am writing a template class which takes a floating-point-like type (float, double, decimal,
interface ICanvasTool { void Motion(Point newLocation); void Tick(); } abstract class CanvasTool_BaseDraw : ICanvasTool
I have the following code... public class Point { private double x; private double
There is a Point (flash.geom.Point) class in as3 I want to add method to
I wrote the following: public class Point { private double _radius , _alpha; public
When I try to create a new instance of the class Point Point nir
Suppose I have something like the following: class Point : geometry { ... Point(double
I have simple class Point with two fields of type double . I asked
Let's say I have a class Point : class Point { public double? x,
public class Array { static String[] a = new String[] {red, green, blue}; static

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.