I'm sorry if the thread title is misleading I solved my initial problem but ran into another one. I'm having some kind of weird problem reading input from a file. It says that my scanner object I'm using to hold an item of information isn't initialized, when I do try to initialize it, it says error variable already initialized. I'm using the scanner to read input from a file whose contents are this
10
150.4
88.4
-3.14
499.4
799.4
1299.8
0
1900.2
901.7
4444.4
This is my program
import java.util.*; import java.io.*; public class QudratullahMommandi_3_07 { Toolkit_General toolKit = new Toolkit_General(); public static void main (String[]args)throws IOException { double rentalCost = 0; double mileage; int controlVar; String inputFile = "QudratullahMommandi_3_07_Output.txt"; SummaryStatement(); File file = new File(inputFile); Scanner inputRead = new Scanner(file); TableHeading(); controlVar = inputRead.nextInt(); for (int index = 0; index < controlVar; index++); { String holder = inputRead.nextLine(); String holder2 = holder2.trim(); mileage = Double.parseDouble(holder2); 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)); } System.out.println(rentalCost); }// end for loop }// 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
QudratullahMommandi_3_07.java:34: error: variable holder2 might not have been initialized
String holder2 = holder2.trim();
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.