Maybe I compare it wrongly and I have strong feeling that I made really simple mistake. I used to programming in C++ and now learning to use Java .In first example .It doesnt print anything
double get_max = Math.max(totalExFood, Math.max(totalExUni, totalExOther ));
double get_min = -Math.max(totalExFood, Math.max(totalExUni,totalExOther ));
double get_mid = (totalExFood +totalExUni + totalExOther) - (get_max + get_min);
String food = ("-Food :RM"+ df.format(totalExFood));
String univ = ("-Univercity :RM"+ df.format(totalExUni));
String othe = ("-Other stuffs :RM"+ df.format(totalExOther));
System.out.println("------------------------------------------------------------------------------");
System.out.println("FINAL REPORT"+"\n");
System.out.println("Total months :"+ size);
System.out.println("Total days :" +totalDay);
System.out.println("Total income :RM" +df.format(totalInc));
System.out.println("Total expense :RM" + df.format(totalExp) );
if((get_max == totalExFood)&& (get_min==totalExUni)){ //testing one value
System.out.println(food);
System.out.println(othe); -------> doesn't print anything
System.out.println(univ);
}
System.out.println("Total saving :RM" + df.format(totalSav));
System.out.println("Overbudget : "+ overBudg+" times");
System.out.println("Most spend :RM" + df.format(max) +"( "+maxMonth+" )");
System.out.println("Average monthly expense :RM" + df.format(avemonthly));
System.out.println("Daily money spend on food :RM "+ df.format(FoodDaily));
I also try using . But this one get error (bad operand types for binary operator '&&')
if((Double.compare(get_max,totalExFood)) && (Double.compare(get_min,totalExUni))){
System.out.println(food);
System.out.println(othe);
System.out.println(univ);
}
Also try this too .Got error (double cannot be dereferenced)
if(get_max.equals(totalExFood) && (get_min.equals(totalExUni)) ){
System.out.println(food);
System.out.println(othe);
System.out.println(univ);
}
first to print max , then print mid , and print min It suppose to look like these : - (highest value first) -Food : RM 400 -Univercity : RM 300 -Other Stuffs : RM 50 or -Univercity : RM 400 -Food : RM 300 -Other Stuffs : RM 50
Aucun commentaire:
Enregistrer un commentaire