Hey guys. Below is an exert from my main class in my java program. I'm needing it to read information from this text file (packages.txt).
But for some reason my "r" is not being recognized as the same "r" from the second line in that txt file(line 28). It's just printing everything in that .txt file when I'm trying to get it to recognize the r and print those sections individuality.
package p02Inheritance; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // Create three packages. System.out.println("Creating two regular, one two-day and one overnight package.\n\n"); Package regular1 = new Package(); File file = new File("packages.txt"); try { Scanner scanner = new Scanner(file); int totalPackages = scanner.nextInt(); System.out.println("Total packages:"+totalPackages+"}"); int debug = 1; while (scanner.hasNextLine()) { String packageType = scanner.nextLine(); System.out.println("{" + packageType + "}");// + (packageType.charAt(1) == 'r') + "}"); if (packageType == "r") { System.out.println("HIT YAYAYAYAYAYAYYAAY"); regular1 = new Package(scanner.next(), scanner.nextDouble(), scanner.nextDouble(), new PersonalInfo(scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next()), new PersonalInfo(scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next())); System.out.println(regular1.toString()); } } } catch (FileNotFoundException e) { e.printStackTrace(); }
But for some reason my "r" is not being recognized as the same "r" from the second line in that txt file(line 28). It's just printing everything in that .txt file when I'm trying to get it to recognize the r and print those sections individuality.
6 r UPS,17.5,0.95,fromFirst1,fromLast1,fromStree1,fromCity1,fromState1,fromZipcode1,toFirst1,toLast1,toStree1,toCity1,toState1,toZipcode1 r FedEx,7.5,1.95,fromFirst2,fromLast2,fromStree2,fromCity2,fromState2,fromZipcode2,toFirst2,toLast2,toStree2,toCity2,toState2,toZipcode2 t 4.95,DHL,10.0,1.15,fromFirst3,fromLast3,fromStree3,fromCity3,fromState3,fromZipcode3,toFirst3,toLast3,toStree3,toCity3,toState3,toZipcode3 o 0.65,UPS,13.0,1.25,fromFirst4,fromLast4,fromStree4,fromCity4,fromState4,fromZipcode4,toFirst4,toLast4,toStree4,toCity4,toState4,toZipcode4 o 0.65,UPS,10.0,1.65,fromFirst5,fromLast5,fromStree5,fromCity5,fromState5,fromZipcode5,toFirst5,toLast5,toStree5,toCity5,toState5,toZipcode5 r DHL,4.5,1.05,fromFirst6,fromLast6,fromStree6,fromCity6,fromState6,fromZipcode6,toFirst6,toLast6,toStree6,toCity6,toState6,toZipcode6