Question

In: Computer Science

Write one Java application based on the following directions and algorithms. Make sure the results from...

Write one Java application based on the following directions and algorithms. Make sure the results from each of the numbered items is separate and easy to read/understand.

1.Create an array that will hold 4 string values. Write three separate statements to store your favorite color, your favorite song, and your favorite restaurant in the array elements. I do not want you to use a loop in this logic; use hard-coded index values instead. Print *ALL FOUR* of the values of the array using individual index values. What is stored in the element you did not fill?

2.Create an array that will hold 5 string values. Use a for loop to prompt the user to enter their 5 favorite movies and store each one in a separate element of the array. Print the values of the array using a For-Each loop.

3.Create an array to hold 7 doubles. Use any looping structure you want to prompt the user to enter a value and store it in the array. In a separate loop, compute the sum of the values. In a third, separate loop, display the array values in reverse order. Also display the sum.

4.Create an array that will hold 3 integers. Without prompting the user for input or using a loop, fill that array with the values 23, 0, and -5. Write decision logic to determine whether the values in each array element is negative, positive, or equal to zero. Make the decision logic loop 3 times, since we want to test 3 different values.

Solutions

Expert Solution

Hi, Please find my implementation.

import java.util.Scanner;

public class ArrayOperation {

   public static void main(String[] args) {

       //1.

       String[] strArray = new String[4];

       strArray[0] = "Yellow"; // favorite color

       strArray[1] = "Wakka Wakka"; // song

       strArray[2] = "Pettu"; //resturant

       System.out.println(strArray[0]);

       System.out.println(strArray[1]);

       System.out.println(strArray[2]);

       System.out.println(strArray[3]);

       System.out.println();

       // null is stored at 3rd location

       //2.

       // to take user input

       Scanner sc = new Scanner(System.in);

       // creating array

       String[] strArr = new String[5];

       // taking user input

       for(int i=0; i<5; i++){

           System.out.print("Enter "+(i+1)+" value: ");

           strArr[i] = sc.nextLine();

       }

       // printing

       for(int i=0; i<5; i++){

           System.out.println(strArr[i]);

       }

       System.out.println();

      

       //3.

       double[] dArr = new double[7];

       // taking user input

       for(int i=0; i<7; i++){

           System.out.print("Enter "+(i+1)+" double value: ");

           dArr[i] = sc.nextDouble();

       }

      

       // computing sum

       double sum = 0;

       for(int i=0; i<7; i++){

           sum = sum + dArr[i];

       }

       System.out.println("Sum: "+sum);

      

       for(int i=6; i>=0; i--){

           System.out.println(dArr[i]);

       }

       System.out.println();

      

       //4.

       int[] iArr = new int[3];

       for(int i=0; i<3; i++){

           if(i==0)

               iArr[i] = 23;

           else if(i == 1)

               iArr[i] = 0;

           else

               iArr[i] = -5;  

       }

      

       for(int i=0; i<3; i++){

           if(iArr[i] > 0)

               System.out.println("Value at "+(i+1)+"th index is positive");

           else if(iArr[i] <0)

               System.out.println("Value at "+(i+1)+"th index is negative");

           else

               System.out.println("Value at "+(i+1)+"th index is zero");

       }

      

   }

}

/*

Sample run:

Yellow

Wakka Wakka

Pettu

null

Enter 1 value: pk

Enter 2 value: mk

Enter 3 value: vk m

Enter 4 value: rk

Enter 5 value: nk

pk

mk

vk m

rk

nk

Enter 1 double value: 3

Enter 2 double value: 2.3

Enter 3 double value: 8.9

Enter 4 double value: 6

Enter 5 double value: 7.8

Enter 6 double value: 9.0

Enter 7 double value: 1.2

Sum: 38.2

1.2

9.0

7.8

6.0

8.9

2.3

3.0

Value at 1th index is positive

Value at 2th index is zero

Value at 3th index is negative

*/


Related Solutions

Write one Java application based on the following directions and algorithms. Make sure the results from...
Write one Java application based on the following directions and algorithms. Make sure the results from each of the bulleted items is separate and easy to read/understand. Create an array that will hold 4 string values. Write three separate statements to store your favorite color, your favorite song, and your favorite restaurant in the array elements. I do not want you to use a loop in this logic; use hard-coded index values instead. Print *ALL FOUR* of the values of...
Write 5+ pages in one of the following topics :- ( MAKE SURE THE HANDWRITING IS...
Write 5+ pages in one of the following topics :- ( MAKE SURE THE HANDWRITING IS READABLE, * I prefer to be made in M.S word ) 1- Contaminant transport in groundwater 2- Modeling of contaminant transport in groundwater
Write a JAVA program that implements the following disk-scheduling algorithms: FCFS
Write a JAVA program that implements the following disk-scheduling algorithms: FCFS
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
Please use Java You have to write a programing for the following sorting algorithms in increasing...
Please use Java You have to write a programing for the following sorting algorithms in increasing order and print required steps in order to explain how your sorting algorithms work. 3. Implement the merge sort algorithm. With answers in this link (https://www.chegg.com/homework-help/questions-and-answers/write-programing-following-sorting-algorithms-increasing-order-print-required-steps-order--q53916147?trackid=PJ_TOK85), answer the above questions.
IN JAVA Implement SRT scheduling algorithms based on following actions: The simulation maintains the current time,...
IN JAVA Implement SRT scheduling algorithms based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to run...
IN JAVA Implement SJF scheduling algorithms based on following actions: The simulation maintains the current time,...
IN JAVA Implement SJF scheduling algorithms based on following actions: The simulation maintains the current time, t, which is initialized to 0 and is incremented after each simulation step. Each simulation step then consists of the following actions: repeat until Rᵢ == 0 for all n processes /* repeat until all processes have terminated */ while no process is active, increment t /* if no process is ready to run, just advance t */ choose active processes pᵢ to run...
Write a java application that will read a set of values from the user and stores...
Write a java application that will read a set of values from the user and stores them in array a[]. The application should ask the user for the number of values he will enter. You need to do the following methods: 1. Read: This method will read n values from the user and store them in an array a 2. Print: this method will print the array as given in the sample output 3. maxEven: This method will find the...
Write a Java program to do the following: Specifics: Write an application that prompts a user...
Write a Java program to do the following: Specifics: Write an application that prompts a user for two integers and displays every integer between them. Display a message if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. Save the file as InBetween.java. Don’t forget to create the application/project  InBetweenTest.java Class that has the main method and an object to use the InBetween class.
Write a Java Program using the concept of objects and classes. Make sure you have two...
Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation) Class Employee Class Variables: Name Work hour per week Hourly payment Class Methods: - Get/Sets - generateAnnualSalary(int:Duration of employment)               annual salary = Hourly payment * Work hours per week * 50 If the employee is working for more than 5 years, 10% added bonus             -void displayAnnualSalary ( )...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT