So my assignment is to read these values from an input file which I previously created. The 10 values represent miles traveled and I convert them using some formula my prof gave me to get the total cost, and output both values to an output file.
My programming question is the first number on the input file isnt a mileage value its the number 10, which is the number of values to be processed, which we're supposed to use in order to control a for or while loop which we'll use to process the contents of the input file. How would I create a while or for loop and get it to skip the first value of the input file?
We're not allowed to use arrays for this assignment.
Also here's my code so far, and it says its not being able to find the file, I made sure the file name is exactly as saved, and its saved in the same directory as the java class that i created for this assignment so I don't see what the problem could be?
Here's my the class with the main method
import java.util.*; import java.io.*; public class QudratullahMommandi_3_07 { public static void main (String[]args) { double rentalCost; double mileage; String inputFile = "QudratullahMommandi_S_07.txt"; SummaryStatement(); File inputSource = new File(inputFile); Scanner input = new Scanner(inputSource); TableHeading(); while (input.hasNext()); { mileage = input.nextDouble(); if (mileage <=0) { System.out.println("*****"); } else if (mileage < 400) { rentalCost = mileage*.18; } else if (mileage < 900) { rentalCost = 65.00 + (.15 * (mileage-400)); } else if (mileage < 1300) { rentalCost = 115.00 + (.12 * (mileage-800)); } else if (mileage < 1900) { rentalCost = 140.00 + (.10 * (mileage-1200)); } else if (mileage < 2600) { rentalCost = 165.00 + (.08 * (mileage-1800)); } else if (mileage >= 2600) { rentalCost = 195.00 + (.06 * (mileage-2500)); } } }// end main public static void SummaryStatement() { System.out.println("This program reads a list of values representing number of miles" + " driven by individuals.\n" + "It will output the dollar amount their rental cars cost."); }// end SummaryStatement public static void TableHeading() { System.out.println(); System.out.println("Number of miles traveled on the left as well as amount reimbursed on the right"); System.out.println("------------------------------------------------"); System.out.println("Miles Driven" + " " + "Amount reimbursed"); } }// end class
This is the error message I get
----jGRASP exec: javac -g QudratullahMommandi_3_07.java
QudratullahMommandi_3_07.java:17: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
Scanner input = new Scanner(inputSource);
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.