Question

JAVA How to add array to develop a contact list application for the person class objects...

JAVA How to add array to develop a contact list application for the person class objects developed in this code?

The application will include functionality to add, remove, sort and search the contact list. You should also include a method to output the contents of a contact searched for, and also to output the entire list.

The code:

package BankProg;

public class personal {
   private String facebook;
   public personal() { }
   public personal(String facebook) {
   this.facebook = facebook;
   }
   public String getfacebook() { return facebook; }
   public void setfacebook(String facebook) { this.facebook = facebook; }

}

----------

public class business {
   private String Companyname, linkedlnlink;
   private long Faxnumber;
   public business() { }
   public business(String Companyname, String linkedlnlink, int Faxnumber) {
   this.Companyname = Companyname;
   this.Faxnumber= Faxnumber;
   this.linkedlnlink = linkedlnlink;
   }
   public String getCompanyname() { return Companyname; }
   public void setCompanyname(String Companyname) { this.Companyname = Companyname; }
   public String getlinkedlnlink() { return linkedlnlink; }
   public void setlinkedlnlink(String linkedlnlink) { this.linkedlnlink = linkedlnlink; }
   public long getFaxnumber() { return Faxnumber; }
   public void setFaxnumber(long Faxnumber) { this.Faxnumber= Faxnumber;
   }
}

----------

public class family {
   private String relationship;

   public family() { }
   public family(String relationship) {
   this.relationship = relationship;
   }
   public String getrelationship() { return relationship; }
   public void setrelationship(String relationship) { this.relationship = relationship;

}
}
----------

public class Person {
   private String name, mailID, address, notes;
   private long phoneNumber, birthday;
   public Person() { }
   public Person(String name, String mailID, String address, int phoneNumber, int birthday, String notes) {
   this.name = name;
   this.mailID = mailID;
   this.address = address;
   this.phoneNumber = phoneNumber;
   this.birthday = birthday;
   this.notes = notes;}
   public String getName() { return name; }
   public void setName(String name) { this.name = name; }
   public String getMailID() { return mailID; }
   public void setMailID(String mailID) { this.mailID = mailID; }
   public String getAddress() { return address; }
   public void setAddress(String address) { this.address = address; }
   public long getPhoneNumber() { return phoneNumber; }
   public void setPhoneNumber(long phoneNumber) { this.phoneNumber = phoneNumber;
   }
   public String getnotes() {return notes;}
   public void setnotes(String notes) { this.notes = notes; }
   public long getbirthday() { return birthday; }
   public void setbirthday(long birthday) { this.birthday = birthday;
   }

   }

----------

public class school {
   private String college, major, degree;
   private long graduationyear;
   public school() { }
   public school(String college, String major, int graduationyear) {
   this.college = college;
   this.major= major;
   this.graduationyear = graduationyear;
   }
   public String getcollege() { return college; }
   public void setcollege(String college) { this.college = college; }
   public String getdegree() { return degree; }
   public void setdegree(String degree) { this.degree = degree; }
   public String getmajor() { return major; }
   public void setmajor(String major) { this.major = major; }
   public long getgraduationyear() { return graduationyear; }
   public void setgraduationyear(long graduationyear) { this.graduationyear= graduationyear;
   }

----------

import java.io.FileOutputStream;
   import java.io.IOException;

   import java.io.PrintStream;

   public class test {

   public static void main(String[] args) throws IOException {
   Person userOne = new Person();
   userOne.setName("jasbin");
   userOne.setAddress("wa");
   userOne.setnotes(" college");
   userOne.setMailID("jasbin888.com");
   userOne.setPhoneNumber(987654321);
   userOne.setbirthday(041430);
   FileOutputStream fileOutputStream = new FileOutputStream("D:/Displayinfo.txt");
   PrintStream printStream = new PrintStream(fileOutputStream);
   printStream.append("Name: " +userOne.getName()+"\r\n");
   printStream.append("Address: " +userOne.getAddress()+"\r\n");
   printStream.append("birthday: "+userOne.getbirthday()+"\r\n");
   printStream.append("notes: "+userOne.getnotes()+"\r\n");
   printStream.append("PhoneNumber: "+userOne.getPhoneNumber()+"\r\n");
   printStream.append("MailID: "+userOne.getMailID()+"\r\n");

   business extraDetailsPerson = new business();
   extraDetailsPerson.setCompanyname("CHINKEN");
   extraDetailsPerson.setlinkedlnlink("[email protected]");
   extraDetailsPerson.setFaxnumber(206356657);
   printStream.append("Companyname: "+ extraDetailsPerson.getCompanyname()+"\r\n");
   printStream.append("linkedlnlink: "+ extraDetailsPerson.getlinkedlnlink()+"\r\n");
   printStream.append("Faxnumber: "+ extraDetailsPerson.getFaxnumber()+"\r\n");

   family details = new family();
   details.setrelationship("father");
   printStream.append("relationship "+ details.getrelationship()+"\r\n");

   personal detail = new personal();
   detail.setfacebook("abs.com");
   printStream.append("facebook "+ detail.getfacebook()+"\r\n");

   school extra = new school();
   extra.setcollege("college");
   extra.setmajor("math");
   extra.setdegree("associate in math");
   extra.setgraduationyear(4);
   printStream.append("college: "+ extra.getcollege()+"\r\n");
   printStream.append("major: "+ extra.getmajor()+"\r\n");
   printStream.append("degree: "+ extra.getdegree()+"\r\n");
   printStream.append("graduationyear: "+ extra.getgraduationyear()+"\r\n");

   System.out.println("Data Added successfully. Please check the text file");

}

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

here is what i made changes .. ok.. i am done with this code ,,, and i am adding the functionality to store the data into ArrayList also to compare remove and search item into it... i hope this will work for you !

here is the code,,, please give me positive rating for my effort ,,, THank You !

the code is --


import java.io.*;
import java.io.IOException;
import java.util.*;
import java.io.PrintStream;

public class test {

public static void main(String[] args) throws IOException {
   Scanner sc=new Scanner(System.in);
   int count=0;
   String ch="Y";
   List list=new ArrayList();
     
   while(ch.equals("Y")){
     
   System.out.println("1. Add contact List \n 2. Remove contact \n 3. Sort contact \n 4. Search Contact \n");
   int choice =sc.nextInt();
   switch(choice) {
         
case 1 : {
count++;
   Person userOne = new Person();
   System.out.print("Enter Person name : ");
   String person=sc.next();
   userOne.setName(person);
   System.out.print("Enter Address : ");
   String address=sc.next();
userOne.setAddress(address);
   System.out.print("Enter College name : ");
   String college=sc.next();

userOne.setnotes(college);
    System.out.print("Enter Email Id : ");
   String email=sc.next();

userOne.setMailID(email);
    System.out.print("Enter Mobile No : ");
   long phonenumber=sc.nextLong();

userOne.setPhoneNumber(phonenumber);
    System.out.print("Enter Date of Birthday : ");
   long dob=sc.nextLong();

userOne.setbirthday(dob);


family details = new family();
System.out.println(" Enter Family detail : ");
System.out.print("Enter the relationship Status : ");
String relationship=sc.next();
details.setrelationship(relationship);
System.out.print("Enter the Facebook id :");
String fid=sc.next();
personal detail = new personal();
detail.setfacebook(fid);

school extra = new school();
System.out.println("Enter the college Name : ");
String collegename=sc.next();
extra.setcollege(collegename);
System.out.println("Enter the subject : ");
String subject=sc.next();
extra.setmajor(subject);
System.out.println("Enter the degree associate subject :");
String subjectdegree=sc.next();
extra.setdegree(subjectdegree);
System.out.println("Enter the gradution year : ");
long year=sc.nextLong();
extra.setgraduationyear(year);


business extraDetailsPerson = new business();
System.out.println("Enter the Extra Detail of Person : ");
System.out.println("Enter the Companyname ");
   String company=sc.next();
extraDetailsPerson.setCompanyname(company);
System.out.println("Enter the email id : ");
String linkedlnlink=sc.next();
extraDetailsPerson.setlinkedlnlink(linkedlnlink);
System.out.println("Enter the Fax Number : ");
long fax=sc.nextLong();
extraDetailsPerson.setFaxnumber(fax);

FileOutputStream fileOutputStream = new FileOutputStream("Displayinfo.txt");
PrintStream printStream=new PrintStream(fileOutputStream);
printStream.append("Name: " +userOne.getName()+"\r\n");
printStream.append("Address: " +userOne.getAddress()+"\r\n");
printStream.append("birthday: "+userOne.getbirthday()+"\r\n");
printStream.append("notes: "+userOne.getnotes()+"\r\n");
printStream.append("PhoneNumber: "+userOne.getPhoneNumber()+"\r\n");
printStream.append("MailID: "+userOne.getMailID()+"\r\n");


printStream.append("Companyname: "+ extraDetailsPerson.getCompanyname()+"\r\n");
printStream.append("linkedlnlink: "+ extraDetailsPerson.getlinkedlnlink()+"\r\n");
printStream.append("Faxnumber: "+ extraDetailsPerson.getFaxnumber()+"\r\n");
printStream.append("relationship "+ details.getrelationship()+"\r\n");
printStream.append("facebook "+ detail.getfacebook()+"\r\n");

printStream.append("college: "+ extra.getcollege()+"\r\n");
printStream.append("major: "+ extra.getmajor()+"\r\n");
printStream.append("degree: "+ extra.getdegree()+"\r\n");
printStream.append("graduationyear: "+ extra.getgraduationyear()+"\r\n");
BufferedReader reader = new BufferedReader(new FileReader("Displayinfo.txt"));
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
reader.close();
     
   System.out.print(list);
     

System.out.println("Data Added successfully. Please check the text file");


   break;
   }
  
   case 2 : {
           System.out.println("Enter the name of the Person : ");
               String nameofperson=sc.next();
               if(list.contains(nameofperson)){
                   list.remove(nameofperson);
                   System.out.println("Detailds Succesfully Removed ..");
               }
               else
               {System.out.println("Name not found ");
               }
               break;
       }
   case 3 : {
         
       list.sort(Comparator.naturalOrder());
       System.out.println("Succesfully Sorted ..");
         
       break;
   }
   case 4 :
   {
       System.out.println("Enter the name of Contact : ");
       String contactperson=sc.next();
       if(list.contains(contactperson))
       {
           System.out.println("Contact found "+ contactperson);
           break;
       }
       else{
             
           System.out.println("Not found ");
           break;
       }
         
   }
   default : System.out.println("Choose option Wisely ...");
      
   }
       System.out.println("Do you want Continue Y/N ");
       ch=sc.next();
   }
   }
}

i only made change into test class ,, it is not purely satisfy you as it have some problem ,,, but i will definaltely share the code whenever i get the right solution for you ,, till then please give me a positive rating to encourage my work and effort ..

here the snapshot of the output --

Thank You !

C:\Users\Aditya kumar\Desktop\chege work\bank account>java test 1. Add contact List 2. Remove contact 3. Sort contact 4. Search Contact Enter Person name : aditya Enter Address : 1 Enter College name : 2 Enter Email Id : Enter Mobile No : 3 Enter Date of Birthday : 3 Enter Family detail : Enter the relationship Status : 3 Enter the Facebook id :3 Enter the college Name : Enter the subject : Enter the degree associate subject : Enter the gradution year : Enter the Extra Detail of Person : Enter the Companyname Enter the email id : Enter the Fax Number : Data Added successfully. Please check the text file Do you want Continue Y/N 1. Add contact List 2. Remove contact 3. Sort contact 4. Search Contact Enter the name of Contact : aditya

Add a comment
Know the answer?
Add Answer to:
JAVA How to add array to develop a contact list application for the person class objects...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • 4. Create a Business class. This class should store an array of Employee objects. Add a...

    4. Create a Business class. This class should store an array of Employee objects. Add a method to add employees to the Business, similar to addFoodItem in the Meal class. Add two more methods for the Business class: getHighestPaid(), which returns the Employee who has been paid the most in total, and getHighestTaxed(), which returns the Employee who has been taxed the most in total. Note: you do not need to handle the case of ties. These are all the...

  • Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models...

    Solve this using Java for an Intro To Java Class. Provided files: Person.java /** * Models a person */ public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) {...

  • PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students...

    PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....

  • Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty...

    Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should set the appropriate field. For setMobile: if the method is passed a valid mobile phone number, it should set the appropriate field; otherwise it should do nothing. A string is a valid mobile phone number if every character in it is a digit from 0 to 9. Hints: To convert a string so you can...

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

  • write a parent class that describes a parcel (like a package, as shown below) and a...

    write a parent class that describes a parcel (like a package, as shown below) and a child class that describes an overnight parcel. Use the provided Address class. A parcel is described by: id (which might contain numbers and letters) weight (described as the number of pounds; a parcel could be less than 1 pound) destination address (uses the provided class) An overnight parcel is described by id, weight, destination address and also: whether or not a signature is required...

  • Write in java and the class need to use give in the end copy it is...

    Write in java and the class need to use give in the end copy it is fine. Problem Use the Plant, Tree, Flower and Vegetable classes you have already created. Add an equals method to Plant, Tree and Flower only (see #2 below and the code at the end). The equals method in Plant will check the name. In Tree it will test name (use the parent equals), and the height. In Flower it will check name and color. In...

  • 1. Employees and overriding a class method The Java program (check below) utilizes a superclass named...

    1. Employees and overriding a class method The Java program (check below) utilizes a superclass named EmployeePerson (check below) and two derived classes, EmployeeManager (check below) and EmployeeStaff (check below), each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Run the program, which prints manager data only using the EmployeePerson class' printInfo method. Modify the EmployeeStaff class to override the EmployeePerson class' printInfo method and print all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT