printf 20s10s15sn nametoLowerCase qty price printWriterprintln else

Printf 20s10s15sn nametolowercase qty price

This preview shows page 3 - 5 out of 5 pages.

printWriter.printf("|%-20s|%10s|%15s|\n", name.toLowerCase(), qty, price); printWriter.println("*************************************************"); } else { System.out.println("\nspecified Item already exists"); System.out.println("Consider adding another " + obj + "\n"); continue; } } System.out.print("If you want to add another " + obj + " press 1, if not press any other character: "); char character = in.next().charAt(0); in.nextLine(); if (character != '1') { printWriter.close(); break; } } } catch (IOException ex) { System.out.println("Exception Occurred: " + ex); } System.out.println("\nData added Successfully..\n"); } private static boolean isPresent(String name, File file) { boolean Found = true; try (Scanner in1 = new Scanner(file)) { while (in1.hasNext()) { String line = in1.nextLine(); String check = line.substring(1, 12); check = check.trim(); if (check.equalsIgnoreCase(name)) { Found = false; break; } } } catch (IOException ex) { System.out.println("Exception: " + ex);
Image of page 3
} return Found; } private static void display(File file) { try { Scanner in1 = new Scanner(file); while (in1.hasNext()) { System.out.println(in1.nextLine()); } } catch (IOException ex) { System.out.println("Exception Occurred: " + ex); } } private static int getInt() { int integer; while (true) { try { integer = in.nextInt(); in.nextLine(); break; } catch (InputMismatchException ex) { in.nextLine(); System.out.println("Input Mis Match Exception Occurred: " + ex); System.out.print("Kindly enter the integer again: "); } } return integer; } private static void EditItem(File file) { System.out.print("Enter the name of the item you want to edit: "); String name=in.nextLine(); if(!isPresent(name,file)){ File fileTemp1=new File("temp1.txt"); try(Scanner sc=new Scanner(file)){ PrintWriter pw=new PrintWriter(fileTemp1); while(sc.hasNext()){ String edit=sc.nextLine(); String line=edit.substring(1,21); line=line.trim(); if(line.equalsIgnoreCase(name)){ sc.nextLine(); continue; } pw.println(edit); } pw.close(); } catch (IOException ex) { System.out.println("Exception: " + ex); } // replacing the old file with the new file after deleting the item from it System.out.println("is old file deleted: " + file.delete()); System.out.println("is temp file renamed: " + fileTemp1.renameTo(file)); } else { // item, user want to delete from list noy present in the list System.out.println("item does not exists.."); }
Image of page 4
} private static void replace() { File fileItem = new File("addItem.txt"); File temp1 = new File("temp1.txt"); if (temp1.exists()) { System.out.println("file item deleted? " + fileItem.delete()); System.out.println("temp1 renamed? " + temp1.renameTo(fileItem)); } } }
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Spring '17
  • Ijlal

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture