Question

In: Computer Science

Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...

Java program

problem 1

  • Come up with an idea for parallel arrays
  • Create the arrays to hold 5 items in each
  • In the main(), load the arrays with data
  • Then output the entire contents of the arrays
  • Create a method called find1() and pass the 2 arrays to that method.

problem 2

  • In the find1() method, ask the user to enter a value to search for
  • Write logic to search the first array and then output the related data from the second array.
  • You can NOT use the .binarySearch() method. Create your own search logic.
  • The find1() method should return a TRUE if a match was found and FALSE if no match was found
    • Be sure to comment your code

Solutions

Expert Solution

Java code:

import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       String countries[] = {"India","US","UK","Srilanka","Bangladesh"};
       String capitals[] = {"Delhi","Washington","London","Colombo","Dhaka"};
       System.out.println("Printing Data in parallel arrays:");
       for(int i=0;i<5;i++)
       {
       System.out.println("Capital of "+countries[i]+" is "+capitals[i]);
       }
       System.out.println("-------------------------------------");
       find1(countries,capitals);
   }
   static boolean find1(String countries[],String capitals[])
{
String key;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Capital for search:");
key = sc.next();
for(int i=0;i<countries.length;i++)
{
if(key.equals(countries[i]))
{
System.out.println("key matched and its corresponding Capital is "+capitals[i]);
return true;
}

}
return false;
  
}
  
}

Execution Screenshots:


Related Solutions

how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them array1 and array 2) Add the two 3Darrays together and then get the average. Save the average on a separate 3D array.(lets name it array3) Then add array1 and array3 then get the average Save the average on a separate 3Darray(lets name it array 4) Then add array2 and array3 then get the average Save the average on a separate 3Darray (lets name it...
Problem 1: In java Create a program to calculate interest rate and total balance - the...
Problem 1: In java Create a program to calculate interest rate and total balance - the program consists of (a) A class that encapsulates the interest rate and total balance calculation Constructor should accept initial balance and interest rate Methods: Returns interest rate Returns total balance Set interest rate Set initial balance (b) A test program that uses class from step (A) to perform the following: Set interest rate to 5% and initial balance to 1000 Print interest amount and...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem....
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem. In this you will use ques and random number generator to complete this project. You will create three queues Couch - the area where patron will wait just prior to getting their hair cut; Line - the area where patron will form a line just before reaching the couch; and Cashier - the area where patrons will line up to pay just before exiting...
1. I need a java program that prints the following rows of arrays, like shown [3,5,6...
1. I need a java program that prints the following rows of arrays, like shown [3,5,6 7, 61, 71, 9, 99, 999, 4, 1, 0] 2. I also need a program that prints the sum of all the arrays 3. and a third program that only prints the elements from row one. Thanks!
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays,...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays, the type of item, its cost, and the number in stock. The program should output this information in the form of a table. The output will look something like below. Also, assume for a finite number of item name of 3 Item Name Cost Number in Stock Widget 25.00 4 ... ... ... Wombet 47.50 9 Prelude to Programming (6th edition)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT