marchbaby
asked on
Java syntax array double question
Hi!
ok, rewritten quite a bit of my code, but I have this:
salesData[currentSalesman] .setloanAm ount(newDa ta[2]);
salesData[currentSalesman] .setintere stRate(new Data[3]);
salesData[currentSalesman] .settermYe ars(newDat a[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!
ok, rewritten quite a bit of my code, but I have this:
salesData[currentSalesman]
salesData[currentSalesman]
salesData[currentSalesman]
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!
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
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
ASKER
It's a String
ASKER
public static String[] getStringArray() {
String[] currentStringArray = new String[7];
currentStringArray[0] = salesData[currentSalesman] .getName() ;
currentStringArray[1] = salesData[currentSalesman] .getmortPh one();
currentStringArray[2] = salesData[currentSalesman] .getloanAm ount();
currentStringArray[3] = salesData[currentSalesman] .getintere stRate();
currentStringArray[3] = salesData[currentSalesman] .gettermYe ars();
return currentStringArray;
String[] currentStringArray = new String[7];
currentStringArray[0] = salesData[currentSalesman]
currentStringArray[1] = salesData[currentSalesman]
currentStringArray[2] = salesData[currentSalesman]
currentStringArray[3] = salesData[currentSalesman]
currentStringArray[3] = salesData[currentSalesman]
return currentStringArray;
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
ASKER
Thank you!!
Oops
currentStringArray[3] = Double.toString(salesData[currentSalesman].getinterestRate());
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);
:)
setX will have to be called with a numeric primitive - your code is passing an array at the moment