user3358266
user3358266

Reputation: 29

How can I store a bunch of double in a single double?

I edited my post. :: New logic problem, everytime I input only 1 integer the += only prints 0.

        System.out.print("\nEnter the property code: ");
                        sPropertyCode = input.next();
                        bError = false; //set to false 
                        dTotalCommission += dCommissionRate;
                        dTotalSales += dSellPrice;

    if (sPropertyCode.equalsIgnoreCase("R"))//if r or R dRate will store 7,...perform calculation for dCommissionRate
                    {
                        dRate = 7;
                        dCommissionRate = dSellPrice * (dRate/100);
                        System.out.print("Total commission on this property is $" +dCommissionRate);
                    } //this works and prints the calculated amount of rate but when it is going to the last line....


if (sYesOrNo.equalsIgnoreCase("n"))
            {
                System.out.println(sApplicationReport);//prints the Summary Report
                System.out.println ("----------------------------------------------------------");
                System.out.println ("Total property sales: $" + dTotalSales);//all the stored values for dSellPrice will be added and printed
                System.out.println("Total Commissions: $"+ dTotalCommission);//This part only prints 0.00 instead of the calcuated dCommissionRate
                break;
            }

Upvotes: 0

Views: 121

Answers (4)

Zied R.
Zied R.

Reputation: 4964

dTotalPrice += dSellPrice 

means : dTotalPrice = dTotalPrice + dSellPrice

But if you want to store 10000 and 20000 in a single variable , you can use an arrayList :

Example :

 ArrayList<Double> myValues = new ArrayList<Double>();
 myValues.add(10000 );
 myValues.add(200O00 );
// etc.

If you want to show them :

 for(int i = 0 ; i < myValues.size(); i++){
    Double mySingleValue = myValues.get(i);
    System.out.println(mySingleValue.toString());
 }

Upvotes: 3

Spaced
Spaced

Reputation: 55

Instead of trying to store multiple doubles in a single double variable, why not try and store your multiple doubles in an array? Therefore you could store your multiple number values in this array and then pick out the ones you want.

Upvotes: 2

IAmTheAg
IAmTheAg

Reputation: 351

Hm. It's kind of hard to follow your thinking, but here is my best shot.

Your code here (dTotalPrice += dSellPrice) Will add the value of dSellPrice to dTotalPrice.

aside from a semicolon you aren't missing anything.

Upvotes: 2

Caffeinated
Caffeinated

Reputation: 12484

You'd just reassign the variable. No problem.

Try it!

double dada = 10.7;

/* run jump play */

dada = 3.141592653589;

However, what makes more sense is to use an array.

declare a double array -

double[] myNumbers = {28.3, 21.2};

Upvotes: 0

Related Questions