OOP-Assignment-2.docx - package daewoo.management.system import java.io import java.util. import java.util.Scanner public class Passengers public static

OOP-Assignment-2.docx - package daewoo.management.system...

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

package daewoo.management.system;import java.io.*;import java.util.InputMismatchException;import java.util.Scanner;public class Passengers {public static File file = new File("Passengers.txt");public static Scanner input = new Scanner(System.in);private int p_id;private String name;private String cnic;private String mob_no;public Passengers() {p_id = 0;name = "Not Assigned";cnic = "Not Assigned";mob_no = "Not Assigned";}public Passengers(int p_id, String name, String cnic, String mob_no) {this.p_id = p_id;this.name = name;this.cnic = cnic;this.mob_no = mob_no;}public void setID(int p_id) {this.p_id = p_id;}public void setName(String name) {this.name = name;}public void setCnic(String cnic) {this.cnic = cnic;}public void setMob(String mob_no) {this.mob_no = mob_no;}public int getID() {return p_id;}public String getName() {return name;}public String getCnic() {return cnic;}public String getMob() {return mob_no;}public String toString() {return (p_id + "\t" + name + "\t\t" + cnic + "\t\t" + mob_no);
Background image
}public boolean equals(Passengers p) {if (this.p_id == p.p_id) {return true;} else {return false;}}public static void addPassenger(Passengers p) {p = new Passengers();System.out.print("\nEnter Passenger's ID: ");p.setID(input.nextInt());p.checkID(p, p.getID());System.out.print("Enter Passenger's Name: ");p.setName(input.next());System.out.print("Enter Passenger's CNIC(XXXXX-XXXXXXX-X): ");p.setCnic(input.next());System.out.print("Enter Passenger's Mobile No(XXXX-XXXXXXX): ");p.setMob(input.next());System.out.println();PrintWriter pw = null;try {pw = new PrintWriter(new FileWriter(file.getAbsolutePath(), true));pw.println(p.toString());pw.close();} catch (IOException e) {System.out.println(e);}}public void checkID(Passengers p, int ID) {Scanner read = null;if (file.exists()) {try {read = new Scanner(file);while (read.hasNext()) {String line = read.nextLine();String[] token = line.split("\\s+");
Background image
Image of page 3

You've reached the end of your free preview.

Want to read all 6 pages?

  • Fall '17
  • Dr. Faisal Cheema
  • Passenger, CNIC, public class Passengers, public static File file

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture