• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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!
0
marchbaby
Asked:
marchbaby
  • 5
  • 4
  • 2
1 Solution
 
CEHJCommented:
What type is 'salesData'?

setX will have to be called with a numeric primitive - your code is passing an array at the moment
0
 
for_yanCommented:
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
0
 
marchbabyAuthor Commented:
It's a String
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
marchbabyAuthor Commented:
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;
0
 
marchbabyAuthor Commented:
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.
0
 
CEHJCommented:
Yes:

>>currentStringArray[3] = salesData[currentSalesman].getinterestRate();

(similar with Integer.toString for the other(s))
currentStringArray[3] = Double.toString(salesData[currentSalesman].getinterestRate()_;

Open in new window

0
 
marchbabyAuthor Commented:
Thank you!
0
 
marchbabyAuthor Commented:
Thank you!!
0
 
CEHJCommented:
Oops
currentStringArray[3] = Double.toString(salesData[currentSalesman].getinterestRate());

Open in new window

0
 
for_yanCommented:
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


0
 
CEHJCommented:
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now