java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Billing.main(Billing.java:20)
import java.util.Scanner;
import java.io.*;
import java.text.NumberFormat;
public class Billing
{
public static void main(String [] args) throws IOException
{
File input = new File("F:\\sprayingdata.txt");
Scanner scan = new Scanner(input);
int clientNumber,type=1,acres,number,total,counter;
double amountDue=1;
{
clientNumber = scan.nextInt();
while(clientNumber < 9999)
type = scan.nextInt();
scan.nextLine();
acres = scan.nextInt();
scan.nextLine();
scan.close();
total = acres = 0;
System.out.println("-----Client Number-----" + "-----Type-----"+ "-----Acres-----"+ "-----Amount Due-----");
System.out.println(("-----" + clientNumber + "-----") + ("-----" + type + "-----")+ ("-----" + acres +"-----") + ("-----" + amountDue + "-----"));
total += type;
acres++;
}
if (clientNumber==0)
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
amountDue = calculateBill(type,acres);
fmt.format(amountDue);
amountDue = (double) total/acres;
System.out.println("The total bill is: " + acres + " numbers is " + amountDue);
}
else
System.out.println("Please enter a valid account number.");
}
public static double calculateBill(int type,int acres)
{
int multiplier;
double grossBill;
if (type==1)
multiplier=1;
else if (type==2)
multiplier=3;
else if (type==3)
multiplier=4;
else if (type==4)
multiplier=6;
else
return -1;
grossBill = multiplier * acres;
if (acres > 1000)
grossBill -= 0.05 * grossBill;
if (grossBill > 1500)
grossBill -= 0.1 * (grossBill - 1500);
return grossBill;
}
}
I am trying to read following data from a text file using Scanner class:
1000 1 1200
1001 2 800
1002 3 300
1003 6 1100
1004 3 783
1005 1 1550
1006 5 950
1007 1 750
1008 2 1050
1009 2 600
1010 4 700
1011 3 1200
1012 3 0
0 0 0
I think data is not being read from the text file properly. Any hints or clues will be greatly appreciated. Thanks.

New Topic/Question
Reply



MultiQuote



|