OOP-Assignment no 2 Solution(Manager Class).docx - Manager Class package newpackage import java.util.Scanner import java.io import

OOP-Assignment no 2 Solution(Manager Class).docx - Manager...

This preview shows page 1 - 4 out of 9 pages.

“Manager Class” package newpackage; import java.util.Scanner; import java.io.*; import java.util.Objects; /** * * @author Abdullah Shahid */ public class Manager { private String CNIC, Name, Contact_No, Email; private int Revenue; public Manager() { } public Manager(String CNIC, String Name, String Contact_No, String Email, int Revenue) { this.CNIC = CNIC; this.Name = Name; this.Contact_No = Contact_No; this.Email = Email; this.Revenue = Revenue; } public String getCNIC() { return CNIC; } public String getName() { return Name; } public String getContact_No() { return Contact_No; } public String getEmail() { return Email; } public int getRevenue() { return Revenue; } public void setCNIC(String CNIC) { this.CNIC = CNIC; } public void setName(String Name) {
Image of page 1
this.Name = Name; } public void setContact_No(String Contact_No) { this.Contact_No = Contact_No; } public void setEmail(String Email) { this.Email = Email; } public void setRevenue(int Revenue) { this.Revenue = Revenue; } @Override public String toString() { return "CNIC: " + CNIC + ", Name: " + Name + ", Contact_No: " + Contact_No + ", Email: " + Email + ", Revenue: " + Revenue ; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Manager other = (Manager) obj; if (this.Revenue != other.Revenue) { return false; } if (!Objects.equals(this.CNIC, other.CNIC)) { return false; } if (!Objects.equals(this.Name, other.Name)) { return false; } if (!Objects.equals(this.Contact_No, other.Contact_No)) { return false; } if (!Objects.equals(this.Email, other.Email)) { return false; } return true; } Scanner input = new Scanner(System.in); // Scanner object to take input from user File file = new File("Manager.txt"); // File object to get the properties of the text file PrintWriter pw; // print writer object to store data in file
Image of page 2
public boolean Add_Manager(String CNIC, String Name, String Contact_No, String email) { FileWriter fw; try { Scanner FileInput = new Scanner(file); // Scanner object to get input from text file int SerialNumber = 0; while (FileInput.hasNext()) { /* this while loop is used to get the last serial number from the text file so that new serial number can be assigned to new record */ SerialNumber = FileInput.nextInt(); String CNIC_ = FileInput.next(); String name = FileInput.next(); String contact = FileInput.next(); String EMAIL = FileInput.next(); int Earnings = FileInput.nextInt(); } FileInput.close(); fw = new FileWriter(file, true); // this object adds new record to the text file without removing the prevoius one pw = new PrintWriter(fw); pw.println((SerialNumber + 1) + " " + CNIC + " " + Name + " " + Contact_No + " " + email + " " +
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 9 pages?

  • Spring '17

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture