Hey,
I am trying to have the user input an integer, a float, and a double. For example:
Input the Integer: 7
Input float: 7
Input the double: 66.4
And then display the following output:
THe integer is: 7 The float is: 7.0 The double is: 66.4
My code runs fine, however it only produces the output for an integer, and leaves the float / double as 0.0 :
THe integer is: 7 The float is: 0.0 The double is: 0.0
I have 2 separate files "Show.java" and "UtilShow.java". The code for both of them is below:
Show.java file
public class Show
{
private int Integer;
private float Float;
private double Double;
public Show (int inTeger )
{
Integer = inTeger;
}
public Show (float fLoat)
{
Float = fLoat;
}
public Show (double douBle)
{
Double = douBle;
}
public void Display()
{
System.out.println("THe integer is: " +Integer + " The float is: " +Float + " The double is: " +Double);
}
}
UtilShow.java file
import java.io.*;
public class UtilShow{
public static void main(String[] args)
{
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("Input the Integer: ");
Show intone = new Show(Integer.parseInt(br.readLine()));
System.out.print("Input float: ");
Show fone = new Show(Float.parseFloat(br.readLine()));
System.out.print("Input the double: ");
Show done = new Show(Double.parseDouble(br.readLine()));
intone.Display();
}
catch(Exception e) {}
}
}
Can anybody please help me out? Thanks alot!