Java double. MAX_ VALUE?

Hello, I was in my first year of computing system development, so I am very new to Java and have mastered the basic knowledge!

For my first task, I must create a gas meter system for the gas company to allow employees to create new customer accounts and modify data such as name and unit cost and deposit (deposit) funds from the accounts

I created my constructor and even added an overloaded method, although I was experiencing a problem. When I started one of my methods, I named the deposit, which should be the money from the user account, while other methods, such as recordunits, allowed employees to import a gas meter, read the number of units used by the customer, and update the balance of the customer account, which was actually owed by the customer to the company

When trying to start the deposit method, I only need the preset information to test the program, and I get this

Account.deposit(Double.MAX_VALUE);

I'm not sure what this means. It seems that I can't find the past! Apologize if this has been released, although I don't see the appropriate answer around

Test data and codes are as follows:

public class TestGasAccount 

{
    public static void main (String [] args)
    {
        GasAccount Account = new GasAccount (223,"Havana","TQ",1000);


        Account.getAccNo();
        Account.getName();
        Account.getAddress();
        Account.getUnits();
        Account.getBalance();
        Account.recordUnits(1000);
        Account.getUnits();
        Account.getBalance();
        Account.deposit(Double.MAX_VALUE);
    }
}

break

public class GasAccount 
{
    private int intAccNo;
    private String strName;
    private String sTraddress; 
    private double dblBalance;
    private double dblUnits;
    protected double dblUnitCost = 0.02; 

     public GasAccount(int intNewAccNo,String strNewName,String strNewAddress,double dblNewUnits)
     {
         intAccNo = intNewAccNo;
         strName = strNewName;
         sTraddress = strNewAddress;
         dblUnits = dblNewUnits;
         dblBalance = dblNewUnits * dblUnitCost;
     }

     public GasAccount (int intNewAccNo,String strNewAddress)
     {
         intAccNo = intNewAccNo;
         strName = strNewName;
         sTraddress = strNewAddress;
     }

     public double deposit (Double dblDepositAmount)
     {
        dblBalance = dblBalance - dblDepositAmount; 
        return dblBalance;
     }

     public String recordUnits (double dblUnitsUsed)
     {
         double dblTempBalance;

         dblTempBalance = dblUnitsUsed * dblUnitCost;
         dblBalance = dblBalance + dblTempBalance;
         dblUnits = dblUnits + dblUnitsUsed;

         return "Transaction Successful"; 
     }

     public int getAccNo ()
     {
         System.out.println(intAccNo);
         return intAccNo;
     }

     public String getName()
     {
         System.out.println(strName);
         return strName; 
     }

      public String getAddress()
     {
         System.out.println(sTraddress);
         return strName; 
     }

     public double getBalance()
     {
         System.out.println("£"+dblBalance);
         return dblBalance; 
     }

     public double getUnitCost()
     {

         return dblUnitCost;
     }

     public double getUnits ()
     {
         System.out.println(dblUnits);
         return dblUnits;
     }

     public void updateUnitCost (double dblNewUnitCost)
     {
         dblUnitCost = dblNewUnitCost;

     }

}

This is just the bare bones of my code. I have more to go, but it will be hoped to give you an idea

Thank you first

Solution

Double. MAX_ Value is the maximum value of double representation (about 1.7 * 10 ^ 308)

If you try to subtract the maximum possible value of the data type, you should end up in some calculation problems

Even when dealing with money, floating-point values should not be used, especially when rounding this problem may cause problems (then your system has much less money)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>