Write a program that implements a rudimentary name-finder. It should start out by filling up a name ArrayList with Name objects. Then it should ask the user if he/she wants to find a particular name. Then it should search for the name in the name ArrayList and return the names information if the name is found. Here is a suggested UML class diagram:
Implement Name filltheblackbook method by adding anonymous objects representing these four names:
First Name Last Name Address
Sara Smith 123 N 53rd
Lolita Edwards 672 E 22nd
Kyle Johnson 456 W 29th
Elizabeth Waitsmith 521 S 3rd
Implement Name’s getName method so that if the name is not found, the method returns the string:
"Sorry – that name is not in the black book."
Implement Name’s toString method simply by returning this string value:
First Name + " " + Last Name + " " + Address
comments and output attached
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author prmsh
*/
public class nameFinder {
String firstName,lastName,address;
//constructor declared
public nameFinder(String firstName, String lastName, String
address) {
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
//getter method
public String getFirstName() {
return firstName;
}
//toostring method
@Override
public String toString() {
return "nameFinder{" + "firstName=" + firstName + ", lastName=" +
lastName + ", address=" + address + '}';
}
public static void main(String args[]){
//arrylist declared to store objects
ArrayList <nameFinder> InfoList = new
ArrayList<nameFinder> ();
Scanner sc = new Scanner(System.in);
while(true){
//menu printing
System.out.println("Enter 1.Add 2.search 3. Exit");
int choice = sc.nextInt();
sc.nextLine();
if(choice == 1){//creating new oibject and adding to list
System.out.println("Enter First name: ");
String firstname = sc.nextLine();
System.out.println("Enter Last name: ");
String lastname = sc.nextLine();
sc.nextLine();
System.out.println("Enter address: ");
String address = sc.nextLine();
sc.nextLine();
nameFinder obj = new nameFinder(firstname,lastname,address);
InfoList.add(obj);
}
else if(choice == 2){ //searching by name
System.out.println("Enter name to search: ");
String name = sc.nextLine();
int count=0;
for (int i = 0; i < InfoList.size(); i++) {
if(InfoList.get(i).getFirstName().equals(name)){
System.out.println(InfoList.get(i));
count++;
}
}
if(count == 0){
System.out.println("No name found in the list");
}
}
else{//exiting from App
System.out.println("Thanq U");
break;
}
}
}
}
output
Write a program that implements a rudimentary name-finder. It should start out by filling up a...
1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...
User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...
Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...
Question 1 (4 mark): Implement a program with two classes according to the following UML diagram: College -firstLab Student: StudentAccount - secondLab Student: StudentAccount +main (String (1) : void +College (String, String, int, int) : +printStudents(): void contains StudentAccount -name: String -studentNumber: int StudentAccount (String, int): +getName(): String +getStudentNumber(): int 2 REQUIREMENTS • The constructor College (String, String, int, int) shall create two component objects of type StudentAccount, i.e., the first lab student and the second lab student, and initialize...
In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...
Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables and toString() method that returns String representation of the river. Class CTRivers describes collection of CT rivers. It has no data, and it provides the following service methods. None of the methods prints anything, except method printListRec, which prints all rivers. // Prints all rivers recursively. Print them is same order as they were in the list . List can be empy...
JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...