Link to home
Start Free TrialLog in
Avatar of marchbaby
marchbaby

asked on

Java syntax array double question

Hi!

ok, rewritten quite a bit of my code, but I have this:

 salesData[currentSalesman].setloanAmount(newData[2]);
                salesData[currentSalesman].setinterestRate(newData[3]);
                salesData[currentSalesman].settermYears(newData[4]);

which is for a String, but loanAmount and interestRate are doubles and termYears is an int. How do I write this then?

Thank you in advance!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What type is 'salesData'?

setX will have to be called with a numeric primitive - your code is passing an array at the moment
You can't have array with elements of different type
You rather have object
salesData

and it should have fiields

double Amount;
doubl interstRate;
int termYears

and mthods

setAamount(doubl amount)

setInterestRate(double rate)
 
setTerm(int year)

and corresponding gett methods
That woulsd be morer logical
Avatar of marchbaby
marchbaby

ASKER

It's a String
public static String[] getStringArray() {
          String[] currentStringArray = new String[7];
          currentStringArray[0] = salesData[currentSalesman].getName();
        currentStringArray[1] = salesData[currentSalesman].getmortPhone();
        currentStringArray[2] = salesData[currentSalesman].getloanAmount();
        currentStringArray[3] = salesData[currentSalesman].getinterestRate();
        currentStringArray[3] = salesData[currentSalesman].gettermYears();

        return currentStringArray;
ok I thought I could do something with Double.toString, but I didn't know how to word it (for lack of a better term.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!
Thank you!!
Oops
currentStringArray[3] = Double.toString(salesData[currentSalesman].getinterestRate());

Open in new window

Something like thate - you define class
and then you can operated withn
the array of instances of this class

class  SalesData {

double amount;
doubl interstRate;
int termYears


public void setAmount(double d){
amount = d;
}

public void setInterestRate(doubel d){
interetRate = d;
}

public void setTerm(int i){
termYears = i;
}

}


SalesData [] sales;

sales = new SalesData[10];

sales[i].setAmount(100000.0);
sales[i].setInterestRate(0.053);
sale[i].setTermYear(20);

Open in new window


:)