This is the code I am using for my program
import java.util.*;
import java.io.*;
import java.util.ArrayList;
/**
* This program will read the information from the
* txt file and will organize and output the information
* in a clean and understandable manner
*/
public class Project3_S_B {// Open class container
public static void main(String[] args) throws FileNotFoundException { // Open main method
File file = new File("M:\\Rooms2.txt"); //This gets the txt file from my computers file explorer
Scanner txtFile = new Scanner(file); //This scans the txt file that was pulled from my computer
String roomName =""; //variable that will hold the value for the name of each room
String roomShade = ""; //variable that will hold the value for the shade choice chosen
String acType = ""; //variable that will hold the value for Air Conditioner type
String acManufacturer = ""; //variable that will hold the value for the Air Conditioner manufacturer
double roomLength = 0.0; //variable that will hold the value for the rooms length
double roomCoolingCapacity = 0.0; //variable that will hold the value for the rooms cooling capacity
Double acCoolingCapacity = 0.0;
double roomWidth = 0.0; //variable that will hold the value for the rooms width
ArrayList<Room> room = new ArrayList<Room>(); //This is the array list for the room name and its information
ArrayList<AirConditioner> airconditioner = new ArrayList<AirConditioner>(); //This is the array list for the Air Conditioner and its information
while(txtFile.hasNext()){ //This while loop will organize the information from the txt file into its categories
txtFile.next();
roomName = txtFile.next();
roomLength = txtFile.nextDouble();
roomWidth = txtFile.nextDouble();
roomShade = txtFile.next();
acManufacturer = txtFile.next();
acType = txtFile.next();
acCoolingCapacity = txtFile.nextDouble();
txtFile.nextLine();
if(txtFile.hasNext()){ //This will repeat the while loop if there arew more lines than the while loop accounts for
txtFile.nextLine();
txtFile.nextLine();
}
Room r = new Room(roomName, roomLength, roomWidth, roomShade);
room.add(r);
AirConditioner a = new AirConditioner(acManufacturer, acType, roomCoolingCapacity);
airconditioner.add(a);
}
for(int i =0; i < room.size(); i++){ //This for loop will output the information from the txt file
System.out.println("Room Name: " +room.get(i) .getroomName());
System.out.println("Room Area(in square feet): " +room.get(i) .getroomArea());
System.out.println("Amount of Shade: " +room.get(i) .getroomShade());
System.out.printf("BTU Per hour needed: %,.0f", room.get(i) .calroomCoolingCapacity());
System.out.println("Air Conditioner Manufacturer: " +airconditioner.get(i) .getacManufacturer());
System.out.println("Air Conditioner Type: " +airconditioner.get(i) .getacType());
System.out.printf("Air Conditioner Cooling Capacity (BTUs Per Hour): %,.0f" +airconditioner.get(i) .getacCoolingCapacity());
System.out.println("" +room.get(i) .hasAdequateCooling());
}
} //Close main method
} //Close class container
And this is the error that it is giving me when I try to run it
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at Project3_S_B.main(Project3_S_B.java:38)
I looked at all the issues it could have been and all of my data types match up with the ones on the txt file. A friend recommended I try exception handling, but I don't see how I could incorporate that into my code and even if I could, I was instructed not to use it in my code.
Master Bathroom
10
15.5
Abundant
GE
Portable
8000
Master Bedroom
16
16.25
Moderate
Frigidaire
Portable
8000
Living Room
30
25
Little
Whirlpool
Window Mounted
18000
Kitchen
20
12
Moderate
GE
Window Mounted
6000