outprintlnnData added Successfullyn private static boolean isPresentString name

Outprintlnndata added successfullyn private static

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

}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)) {
Background image
Found = false;break;}}} catch (IOException ex) {System.out.println("Exception: " + ex);}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();System.out.println("Enter the quantity of " + name + " :");int qty = getInt();System.out.println("Enter the price of " + name + " : ");int price = getInt();pw.printf("|%-20s|%10s|%15s|\n", name.toLowerCase(), qty, price);pw.println("*************************************************");continue;}pw.println(edit);
Background image
}pw.close();} catch (IOException ex) {System.out.println("Exception: " + ex);}System.out.println("Exit the program and again start the program to view changes...");} else {// item, user want to edit from list not present in the listSystem.out.println("item does not exists..");}}private static void deleteItem(File file) {System.out.print("Enter the item you want to delete: ");
Background image
Image of page 6

You've reached the end of your free preview.

Want to read all 6 pages?

  • Spring '17
  • Ijlal

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture