Question

In: Computer Science

In java, (include javadoc comments for each method) design a class named Contacts that has fields...

In java, (include javadoc comments for each method)
design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works.

Solutions

Expert Solution

public class Main{
public static void main(String args[]){
//create array of Contact object
Contact[] obj = new Contact[2] ;

//create actual Contact object
obj[0] = new Contact();
obj[1] = new Contact();

//assign data to Contact objects
obj[0].setData(1008795,"era","[email protected]");
obj[1].setData(2056840,"XYZ","[email protected]");

//display the Contact object data
System.out.println(" Contact Object 1:");
obj[0].showData();
System.out.println(" Contact Object 2:");
obj[1].showData();
}
}
//Contact class with phone,email and name as attributes
public class Contact{
   int phone;
   String name;
   String email;
   public void setData(int phone,String name,String email){
   int this. phone=phone;
   String this.name=name;
   String this. email=email;
   }

public int getphone() {

        return this.phone;

    }

    public void setphone(int phone) {

        this.phone = phone;

    }

public String getName() {

        return this.name;

    }

    public void setName(int name) {

        this.name= name;

    }

public String getEmail() {

        return this.email;

    }

    public void setEmail(int email) {

        this.email=email;

    }

   public void showData(){
       System.out.print("phone = "+phone + " " + " Name = "+name+" email = "+email);
       System.out.println();
   }
}


Related Solutions

In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
IN JAVA PLEASE, USE COMMENTS Following the example of Circle class, design a class named Rectangle...
IN JAVA PLEASE, USE COMMENTS Following the example of Circle class, design a class named Rectangle to represent a rectangle. The class contains: • Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. • A no-arg constructor that creates a default rectangle. • A constructor that creates a rectangle with specified width and height • A method name getWidth() return the value...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a...
Java program Test Scores? Design a TestScore class that has three integer fields, each holding a test score. The class should have accessor and mutator methods for the test score fields and a method that returns the average of the test scores as a double. Test the TestScore class by writing a separate program that creates an instance of the class. The program should ask the user to enter three test scores, which should be stored in the TestScore object....
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. b. Design an application that declares three BaseballGame objects and sets and displays their values. c. Design an application that declares an array of 12 BaseballGame objects. Prompt the user for...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT