Explanation of Solution
Program:
File name: “PhoneNumbers.java”
//Import necessary header files
import javax.swing.*;
//Define a class named PhoneNumbers
class PhoneNumbers
{
//Define a main method
public static void main(String[] args)
{
/*Declare an array to store first names for 30 people*/
String[] names = new String[30];
//Assign names for 10 people
names[0] = "Gina"; names[1] = "Marcia";
names[2] = "Rita"; names[3] = "Jennifer";
names[4] = "Fred"; names[5] = "Neil";
names[6] = "Judy"; names[7] = "Arlene";
names[8] = "LaWanda"; names[9] = "Deepak";
/*Declare an array to store numbers for 30 people*/
String numbers[] = new String[30];
//Assign numbers for 10 people
numbers[0] = "(847) 341-0912";
numbers[1] = "(847) 341-2392";
numbers[2] = "(847) 354-0654";
numbers[3] = "(414) 234-0912";
numbers[4] = "(414) 435-6567";
numbers[5] = "(608) 123-0904";
numbers[6] = "(608) 435-0434";
numbers[7] = "(608) 123-0312";
numbers[8] = "(920) 787-9813";
numbers[9] = "(930) 412-0991";
//Declare the variables and initialize the value
String entryName, entryPhone;
int x;
boolean isFound = false;
int highest = 10;
//Prompt the user to enter a name
entryName = JOptionPane.showInputDialog(null,
"Enter name to look up. Type 'quit' to quit.");
/*While the user enters a name until the arrays are full
and until the user enters quit*/
while (highest < 30 && !entryName.equals("quit"))
{
//For loop to be executed until x exceeds highest
for(x = 0; x < highest; ++ x)
/*If the name is found in the list, display the
corresponding phone number*/
if(entryName...
Want to see the full answer?
Check out a sample textbook solution- A personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries.arrow_forwardA personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Use the following names and phone numbers: Name Phone # Gina (847) 341-0912 Marcia (847) 341-2392 Rita (847) 354-0654 Jennifer (414) 234-0912 Fred (414) 435-6567 Neil (608) 123-0904 Judy (608) 435-0434 Arlene (608) 123-0312 LaWanda (920) 787-9813 Deepak (930) 412-0991 import java.util.*; class PhoneNumbers { public static void main(String[] args) { // Write your code here } }arrow_forwardCreate a program that allows you to create a fantasy football roster based on the existing list of available players. Your team can only have 5 players, so create an array that can store 5 possible players. Prompt the user to pick 5 players to add to their team. If the player is available in the list of availablePlayers, then add that player to the users array, and remove that player from the availablePlayers list. Then prompt the user to pick another player. Once all five players have been added, then print the list in the console. Create a search method to find the index at which the player is located in the availablePlayers list so you can remove the player, and make sure that they are an eligible pick. Here is a sample run of the program: Enter Player you would like on your team: Cam Newton Great! That player is added to your team! Enter Player you would like on your team: Travis Kelce Great! That player is added to your team! Enter Player you would like on your team: Alvin Kamara…arrow_forward
- JAVA Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students’ grade point averages. Use dialog boxes to accept a student ID number and display the student’s first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number.arrow_forwardIn java, please read the text file as array. Then, replace the null with 0 and calculate the sum of the new students in ABC University.Example of text file: (university,year,total_students,new_students,new_staff,ABC, 2000, 3457, , ,ABC, 2001, 3675,218, ,EFG, 2000, 2389,602, ,EFG, 2001, 2785,396, 65,)arrow_forwardIn this programming challenge, you will create a simple trivia game for two players. The program will work like this: • Read the contents of the trivia.txt file into an ArrayList . • Starting with player 1, each player gets a turn at answering one trivia question. (For instance, if there are 10 questions, 5 for each player.) When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point. • After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner, same as the sample execution. You are to design a Question class to hold the data for a trivia question. The Question class should have String fields for the following data: • A trivia question • Possible answer 1 • Possible answer 2 • Possible answer 3 • Possible answer 4 • The number of the…arrow_forward
- Write a program that deletes the first element in an array which matches a search key. Advance thanks <3arrow_forwardWhich of the following prints the number of elements of the array list? Select one: a. System.out.println(myArrayList.elements()); b. System.out.println(myArrayList.size()); c. System.out.println(myArrayList.size); d. System.out.println(myArrayList.elements);arrow_forwardCreate an array of objects of the Person class, of size 4. Create three objects of the Person class, with values, and assign the objects to the array. Loop through the array and print the name, job, and email of all Personobjects.arrow_forward
- Create an array of objects of the Person class, of size 4. Create three objects of the Person class, with values, and assign the objects to the array. Loop through the array and print the name, job, and email of all Personobjects. (using the Netbeans application (Java)arrow_forwardIn this lab, you will read two files. Firstly, the ‘AccountData.csv’ file has the name and account number.Use each account number to scan the ‘BankData.csv’ file for a matching account number to get a ‘balance’from the account transactions. You must repeatedly open, read the ‘BankData.csv’ file and close it for eachaccount number in the ‘AccountData.csv’ file unless you wish to store its entire contents in a static array.(More code and may not be enough time to complete.) import java.io.*;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import java.util.ArrayList;import java.time.format.DateTimeFormatter; public class BankDataProcessing { static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm"); static ArrayList<BankAccount> Accounts = new ArrayList<>(); public static void main(String[] args) { try { Path path = Paths.get("src/AccountData.csv"); readAccounts(path, true);…arrow_forwardIn the composer array, create a statement that copies the string "Beethoven."arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning