Question

In: Computer Science

In java, (include javadoc comments for each method, please use ArrayList, not Array, and ensure that...

In java, (include javadoc comments for each method, please use ArrayList, not Array, and ensure that the program compiles).
design a class named Contact 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.

Solutions

Expert Solution

import java.util.*;

class Person { //person class
private String PersonName; //string variable for name
private String PhoneNumber; //string variable for number
private String email; //string variable for email
public Person(){ //constructor
  
}
public Person(String a,String b,String c) { //parameterised constructor
this.PersonName = a;
this.PhoneNumber = b;
this.email = c;
}

public String getPersonname() { //getter
return PersonName;
}
public void setPersonname(String a) { //setter
   this.PersonName = a;
}
public String getPhoneNumber() { //getter
return PhoneNumber;
}
public void setPhoneNumber(String a) { //setter
   this.PhoneNumber = a;
}
public String getemail() { //getter
return email;
}
public void setemail(String a) { //setter
   this.email = a;
}
}
public class Main{
public static void main(String args[]){
String a="",b="",c=""; //variable to get user input
Scanner sc=new Scanner(System.in);
ArrayList<Person> p=new ArrayList<Person>(); //list of person
for(int i=0;i<5;i++){
System.out.println("Enter the Person Name: "); //getting details
a=sc.nextLine();
System.out.println("Enter the Person Phone Number: "); //getting details
b=sc.nextLine();
System.out.println("Enter the Person Email: "); //getting details
c=sc.nextLine();
p.add(new Person(a,b,c)); //adding object to list
}
for(int i=0;i<p.size();i++){ //printinng the objects list
System.out.println("Person Name: "+p.get(i).getPersonname()+"Person Phone Number: "+p.get(i).getPhoneNumber()+"Person Email: "+p.get(i).getemail());
}
}
}

Input:

Output:

If you found this answer helpful please give a thumbs up.


Related Solutions

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...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments)...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments) // declare the constructor that sets the type and rate based in the sqft parm        // set values based on sqft <1000 is small with $100 per night, // sqft between 1000 and 2000, mid-sized $200 per night, and // over 2000 as a large cabin with $300 per night        //declare getRate        //declare getType        //declare setRate with int rate parm...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of...
Implement the Nickel class. Include Javadoc comments for the class, public fields, constructors, and methods of the class. I have added the Javadoc comments but please feel free to format them if they are done incorrectly. public class Nickel implements Comparable { private int year; /** * The monetary value of a nickel in cents. */ public final int CENTS = 5; /** * Initializes this nickel to have the specified issue year. * * @param year * * @pre....
Hello, Please write this program in java and include a lot of comments and please try...
Hello, Please write this program in java and include a lot of comments and please try to make it as simple/descriptive as possible since I am also learning how to code. The instructions the professor gave was: Create your own class Your own class can be anything you want Must have 3 instance variables 1 constructor variable → set the instance variables 1 method that does something useful in relation to the class Create a driver class that creates an...
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the...
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the...
Write a java class for a Priority Queue. Use an arraylist, and include enque, deque, and...
Write a java class for a Priority Queue. Use an arraylist, and include enque, deque, and a method to get all the values of the queue. (This is not writing a file implementing the java class PriorityQueue, but rather you are writing a program that is a priority queue).
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
WRITE IN JAVA, please include comments and explain what you did A Book has such properties...
WRITE IN JAVA, please include comments and explain what you did A Book has such properties as title, author, and numberOfPages. A Volume will have properties such as volumeName, numberOfBooks, and an array of book objects (Book [ ]). You are required to develop the Book and Volume classes, then write an application (DemoVolume) to test your classes. The directions below will give assistance. Create a class called Book with the following properties using appropriate data types: Title, Author, numberOfPages,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT