我不确定如何使用数字格式类来将双重格式转换为美国货币。
例如,如果学费是 1000,我需要它打印出 $1,000.00。我会输入一段代码来显示我的问题在哪里。
public double getCurrencyInstance() 是我开始使用的方法,它显然是不正确的。
import java.text.NumberFormat;
public class OnlineStudent extends Student {
private double computingFee;
public double getCurrencyInstance(){
return computingFee;
}
public OnlineStudent(){
super();
}
public OnlineStudent(String fName, String lName, String id, int credits, double rate, double compFee){
super(fName, lName, id, credits, rate);
this.computingFee = compFee;
}
public void computeTuition(){
tuition = (rate + computingFee) * creditNum;
}
public String toString(){
return ("\nOnline Student:\nFirst name:\t\t" + firstName + "\nLast name:\t\t" + lastName + "\nStudent ID:\t\t" + studentID
+ "\nCredits:\t\t" + creditNum + "\nRate:\t\t\t" + super.rate + "\nTuition:\t\t" + super.tuition + "\nComputing Fee:\t\t"
+ getCurrencyInstance() + "\n\n");
}
}