hi, i actually had done similar programs many times and don't know why eclipse gave me strange output this time. anything possibly wrong? thanks
class RobotShop
{
public static void main(String[] args)
{
try
{
Scanner reader = new Scanner(new File("air.txt"));
String robotName = null;
String serial = null;
double price = 0.00;
double flyingSpeed = 0.00;
String airWeapon= null;
while(reader.hasNextLine())
{
robotName = reader.nextLine();
System.out.println(robotName);
serial = reader.nextLine();
System.out.println(serial);
price = reader.nextDouble();
System.out.println(price);
flyingSpeed = reader.nextDouble();
System.out.println(flyingSpeed);
airWeapon= reader.nextLine();
System.out.println(airWeapon);
//FlyingRobot fly = new FlyingRobot(robotName, serial, price, flyingSpeed, airWeapon);
//fly.showInfo();
}
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
}
/*
catch(InputMismatchException e)
{
System.out.println("Input miss match Exception");
}
*/
}
}
my text file is as follow
Black Hawk
A777
7000
150.00
Missle
Killer 571
U571
10000
500
Missle
Air Tran
T389
3000
400
M16
my output is :
Black Hawk
A777
7000.0
150.0
// what made this spaced out????
Missle
Killer 571
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at RobotShop.main(Robot.java:85)