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 solutionChapter 8 Solutions
MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
- a class with 10 students that will take 3 exams use 3 arrays to hold the scores for each student and anoither array to hold the average of the 3 exams for each student. Print the table with the scores and averagearrow_forwardCreate an ArrayList, Named it Husnain that can hold Integers, and fill each slot with a different random value from 1-50. Display those values on the screen, and then prompt the user for an integer to search through the ArrayList, and if the item is present, say so. It is not necessary to display anything if the value was not found. If the item is in the ArrayList multiple times, it's okay if the program prints the message more than oncearrow_forwardFor this exercise, please calculate two values from all of the numbers in the two dimensional array. The first value should be the sum of all numbers in the array. This should be stored in a separate "int" variable that is created outside the nested FOR loops. The second value should be the total average of all numbers in the Array. This should be stored in a separate "float" variable, also outside the nested FOR loop structure. So, in short: • Display the sum of the values in the array • Then display the average of the values in the array Please refer to the sample output below for visualization and match its style. As always: • Remember, the class name should be Lab9B. The user input is indicated in bold. Sample Output #1: Please enter the number of rows: 3 Please enter the number of columns: 2 I have 3 rows and 2 columns. I need to fill-up 6 spaces. The 3x2 array: 1|2| 314| 516| The sum of all the numbers in the 3x2 array: 21 The average of all the numbers in the 3x2 array: 3.5…arrow_forward
- Create an array called sales to monitor one week's worth of sales over the course of two months. Assign sales data to the array's elements. Then, in a loop, compute the average sales for the one week of each of the two months that are recorded in the array.arrow_forwardCreate a class containing the main method. In the main method, create an integer array and initialize it with the numbers: 1,3,5,7,9,11,13,15,17,19 Pass the array as an argument to a method. Use a loop to add 1 to each element of the array and return the array to the main method. In the main method, use a loop to add the array elements and display the result. Note: In the loops, use the array field that holds the length of the array and do not use a number for array length.arrow_forwardWrite a program that asks the user to enter 15 integers into an array. Then ask the user to enter a search value. If the value exists in the array, the program will remove its first occurrence in the array, shifting each subsequent element forward and adding a zero at the end of the array. The program then will display the final contents of the array.arrow_forward
- Create a program that will track student names and their grades and perform some simple statistics. In a main class create an ArrayList or array that will hold Student names. Create a second (parallel) ArrayList or array that will hold student scores, represented as integers from 0-100. Prompt the user to enter some students (for your purposes, enter information for at least three). Then present a menu for the user. The menu will contain the following options: Find student with the highest grade (print out the name of the student) Find grade average (return the grade average back to the calling method) print information of all students exit program Create methods in your main class for these options. Keep the your ArrayList or array inside your main method and pass it to the other methods; it should not be a global variable. Validate the grade; the user should not enter anything below 0 or above 100.arrow_forward4. Create a main method that will create a 2-d array with 4 rows and 5 columns. Call the method from number 3 to fill the array with values. Use a loop to find the max of each row and then curve each row so that the max is turns into 100.arrow_forwardCreate three arrays of size 12 each. The first array will store the first year of energy costs, the second array will store the second year after going green, and the third array will store the difference. Also, create a string array that stores the month names.arrow_forward
- GetMonth - This method prompts for and returns the month GetNumMurals - This method prompts for and returns the number of murals scheduled and is called twice -- once for interior murals and once for exterior murals ComputeRevenue - This method accepts the number of interior and exterior murals scheduled, accepts the month they are scheduled, displays the interior and exterior prices, and then returns the total expected revenue DataEntry - This method fills an array with customer names and mural codes and is called twice -- once to fill the array of interior murals and once to fill the array of exterior murals GetSelectedMurals - This method continuously prompts for mural codes and displays jobs of the corresponding type until a sentinel value is entered. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. in C#arrow_forwardthis practcie assignment wants me to Write an application that contains an array of 10 multiple-choice quiz questions related to your favorite hobby. Each question contains three answer choices. Also create an array that holds the correct answer to each question—A, B, or C. Display each question and verify that the user enters only A, B, or C as the answer—if not, keep prompting the user until a valid response is entered. If the user responds to a question correctly, display Correct!; otherwise, display The correct answer is and the letter of the correct answer. After the user answers all the questions, display the number of correct and incorrect answers . how do i create arrays help!! here is my code that i have so far : import java util.Scanner;public class Quiz {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.println("What is my favorite hobby?\n" + "(a)hair\n(b)makeup\n(c)both a and b\n");System.out.println("Who first discovered makeup?\n"…arrow_forwardthis practice assignement wants me to Write an application that contains an array of 10 multiple-choice quiz questions related to your favorite hobby. Each question contains three answer choices. Also create an array that holds the correct answer to each question—A, B, or C. Display each question and verify that the user enters only A, B, or C as the answer—if not, keep prompting the user until a valid response is entered. If the user responds to a question correctly, display Correct!; otherwise, display The correct answer is and the letter of the correct answer. After the user answers all the questions, display the number of correct and incorrect answers here is my new code! i need help to get it to working : import java.util.*;public class Quiz {public static void main(String args[]){String questions[]=("1.What is my favorite hobby?\n" + "(a)hair\n(b)makeup\n(c)both a and b\n", "2.Who first discovered makeup?\n" +"(a)Egyptians\n(b)haitians\n(c)Africans", "3.What glue is best to use…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT