Question:
java...why isnt it printing the result? i have put a // to where the problem might be?
Akinyo
2012-12-06 02:03:55 UTC
import java.util.Scanner;
public class InputTest {


public static void main(String[] args) {
Calculator calc = new Calculator();
calc.setTarrif(20);
calc.setTar1minuteChargerate(0.10);
calc.setTar1textChargerate(0.05);
Tarrif2 tar = new Tarrif2();
tar.setTarrif(35);
tar.setTar1minuteChargerate(0.10);
tar.setTar1textChargerate(0.05);
Scanner scan = new Scanner(System.in);
System.out.println("Enter tarrif number: ");
int key=scan.nextInt();
if(key==1){


System.out.println("Enter message used: ");
int enter = scan.nextInt();
System.out.println("Enter minutes used: ");
int input = scan.nextInt();
//this is the printing statement
String.format("\nTarrif:\t%s \n:Total Charge\t%s \nBreakdown(Message/Minute charges):\t%s "
,key ,calc.CalcMess(enter)+calc.calcMin(input),calc.CalcMess(enter) );




else if(key==2){
System.out.println("Enter message used: ");
int enter = scan.nextInt();
System.out.println("Enter minutes used: ");
int input = scan.nextInt();
//this is the printing section

String.format("\nTarrif:\t%s \n:Total Charge\t%s \nBreakdown(Message/Minute charges):" +
"\t%s ",key ,tar.CalcMess(enter)+tar.calcMin(input),tar.CalcMess(enter) );


}

}

}
Four answers:
Anita
2012-12-06 02:17:18 UTC
try:



string output = String.format("\nTarrif:\t%s \n:Total Charge\t%s \nBreakdown(Message/Minute charges):" + "\t%s ",key ,tar.CalcMess(enter)+tar.calcMin(input),… );



System.out.println(output);
2012-12-06 10:56:25 UTC
Make a toString method inside the other class



Public String toString(){

return String.format(bla bla bla);

}



and then in the InputTest write

System.out.print(object name here)

It'll work fine(Y)
deonejuan
2012-12-06 12:27:37 UTC
Java has System.out.printf( "%nTarrif:\t%s", dutyTariff );
Laurence I
2012-12-06 10:08:58 UTC
you havnt told it to print anything.

system.out does that



look below, a string is created, and then printed


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...