Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that creates a contact list using an array. The program should contain two classes, a Contact.java class which has the following fields,

Write a program that creates a contact list using an array. The program should contain two classes, a Contact.java class which has the following fields, name, number, and address. The second class, MyContacts.java should present the user with the following options: Add, Remove, Change Order, Print, and Exit. The Add option should allow the user to enter in a new contact (name, number, and address) to the end of the list. The Remove option should print the contact list with its array index. Once a user selects an index, the contact will be deleted from the array and the other items will be moved to fill the spot. The Change Order option will print the contact list with the array index order. The user will be able to enter the numbers. The first number will be the contact they want to move and the second number will be the index to where the first item will be moved. The second contact will be moved to the index of the first. The Print option will print the contact list with the array index and the Exit option will terminate the program.

Below is Contact.java and MyContact.java (it's just a skeleton) I created so far. I think I have a big picture of it but when it comes to the details, I get lost and stuck. Please help.

ublic class Contact { private String name; private int number; private String address;

public Contact(String contactName, int contactNumber, String contactAddress) { this.name = contactName; this.number = contactNumber; this.address = contactAddress; }

public void setName (String contactName) { name = contactName; }

public String getName() { return name; }

public void setNumer(int contactNumber) { number = contactNumber; }

public int getNumber() { return number; }

public void setAddress(String contactAddress) { address = contactAddress; }

public String getAddress() { return address; }

public void display() { System.out.println(" Name: " + name + " Number: " + number + " Address: " + address); }

}

========================================================================================================================================

import java.util.*; public class MyContacts { public static void main(String[] args) { int add = 1; int remove = 2; int change = 3; int print = 4; int exit = 5; int response; Contact[] contacts = new Contact[10]; Scanner input = new Scanner(System.in); System.out.println("Enter" + add +" to Add a new contact," + remove + " to Remove contact, " + change + " to Change Order" + print + " to Print, and " + exit + "to Exit"); response = input.nexntIt();

switch(response) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; default: System.out.println("You entered an invalid number."); } } private add(Contact[] contacts, Contact contact) { } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

Students also viewed these Databases questions

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago