Question

Storing the Array: Write an application that uses an Array to store 10messages of type String....

Storing the Array: Write an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a message could be “I love Java the programming language!” or another message could be “I love Java the drink!”

Initializing the Array: You may initialize your Array with the messages or have the user enter the messages. The choice is yours. Your Java code will contain a method called shoutOutCannedMessage() that will loop through the Array to iterate through your entire list and display each message and allow the user to select one. The shoutOutCannedMessage() will return the selected message String.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
public class Test
{
public static void main(String args[])
{
String[] arr=new String[10];
arr[0]="hi";
arr[1]="hello";
arr[2]="how are you?";
arr[3]="I'm fine";
arr[4]="What is your name?";
arr[5]="where are you?";
arr[6]="how many years?";
arr[7]="your age ?";
arr[8]="your country?";
arr[9]="your father name ?";
System.out.println(" you selected : "+shoutoutCannedMessage(arr));
}
public static String shoutoutCannedMessage(String[] arr)
{
System.out.println("\n Select one of the below \n");
for(int i=0;i<arr.length;i++)
{
System.out.println((i+1)+arr[i]);
}
System.out.println("\n your selection please : ");
Scanner s=new Scanner(System.in);
int n=s.nextInt();
return arr[n-1];
}
}

Output :

Add a comment
Know the answer?
Add Answer to:
Storing the Array: Write an application that uses an Array to store 10messages of type String....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • C coding language is used. Write a program that declare parallel arrays for storing information about...

    C coding language is used. Write a program that declare parallel arrays for storing information about 10 employees. One array will store the hours each person worked for a week and a second array will store each person's weekly pay. Your program should ask the user for the number of hours each of the 10 employees worked. The pay should calculate both regular and overtime pay. Assume that all 10 employees earn $15.25 per hour. Your program should allow the...

  • Write a java application that is including a three-question multiple choice quiz about Java programming language....

    Write a java application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to 4). Also, ask user to type 0 to exit the test. [Assume that a user enters only integers 1,2,3,4, or 0]. Firstly, display a message that this quiz includes three questions about the Java programming language and display that each question has four possible answers. If the answer is correct for the given question,...

  • a. Write an application for Cody's Car Care Shop that shows a user a list of...

    a. Write an application for Cody's Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as $25, $22, $15, or $5, accordingly. Display an error message if the user enters an invalid item. Save the file as CarCareChoice.java. b. It might not be reasonable to expect users...

  • Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items...

    Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when user enter "0", stop the loop. - User enter item name, price, quantity, save these info and subtotal to array. - increase "count++" -conver price(decimal, Convert.ToDecimal() ) and quantity(int) to do mulplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • Write program in JAVA with a method that returns an array. The method should accept as input a co...

    Write program in JAVA with a method that returns an array. The method should accept as input a comma-delimited string with three values from a user. The array should store each value in a different element. Use Try..Catch error handling and print any failure messages, or print success from within method if execution is successful (see Chapter 13 in the text). Call the method from the main method of the program to demonstrate its functionality by looping through the array...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • Write a method will accept an array of Strings. This method should return the string that...

    Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT