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 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 the array using individual index values. What is stored in the element you did not fill? (type your answer in a single line comment within your program)
  • 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.
  • 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.
  • 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

// Java program to perform operations on array

public class ArrayManip

{

public static void main(String[] args) {

      

             Scanner scan = new Scanner(System.in);

            

             String strValues[] = new String[4];

             strValues[0] = "Color1";

             strValues[1] = "Song1";

             strValues[2] = "Restaurant1";

             System.out.println("String values in the array : ");

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

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

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

             System.out.println(strValues[3]); // The element that is not filled contains null

             System.out.println();

             // Create an array that will hold 5 string values.

             String movies[] = new String[5];

             // for loop to prompt the user to enter and store their 5 favorite movies

             for(int i=0;i<movies.length;i++)

             {

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

                    movies[i] = scan.nextLine();

             }

            

             System.out.println("For each loop to print the movies : ");

             // Print the values of the array using a For-Each loop.

             for(String s: movies)

             {

                    System.out.println(s);

             }

             System.out.println();

             // Create an array to hold 7 doubles.

             double dblValues[] = new double[7];

            

             // loop to prompt the user to enter a value and store it in the array

             for(int i=0;i<dblValues.length;i++)

             {

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

                    dblValues[i] = scan.nextDouble();

             }

            

             // In a separate loop, compute the sum of the values.

             double sum = 0;

             for(int i=0;i<dblValues.length;i++)

             {

                    sum += dblValues[i];

             }

             System.out.println("Sum of elements : "+sum); // print the sum of the values

            

             System.out.println("Elements in reverse order : ");

             //In a third, separate loop, display the array values in reverse order.

             for(int i=dblValues.length-1;i>=0;i--)

             {

                    System.out.print(dblValues[i]+" ");

             }

             System.out.println("\n");

             int intValues[] = {23,0,-5}; // Create an array that will hold 3 integers with the values 23, 0, and -5

            

             // loop to print if the values are positive, negative or zero

             for(int i=0;i<intValues.length;i++)

             {

                    if(intValues[i] < 0)

                           System.out.println(intValues[i]+" is negative");

                    else if(intValues[i] > 0)

                           System.out.println(intValues[i]+" is positive");

                    else

                           System.out.println(intValues[i]+" is zero");

             }

        }

}

//end of program

Output:

The element in the String array which was not filled stores null.


Related Solutions

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
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 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 ( )...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java...
1. a) Write two algorithms of different time complexity implemented in Java methods in complete Java program to reverse a stack of characters. Make your own assumption and your own design on the methods signature, inputs, outputs, and the full main program.
This is a Java program Problem Description Write an application that inputs five digits from the...
This is a Java program Problem Description Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits. Sample Output Enter five digits: 1 2 3 4 5 The number is 54321 Problem-Solving Tips The input digits are integer, so you will...
in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
Write a Java application that checks a string for correct parenthesization. The input comes from the...
Write a Java application that checks a string for correct parenthesization. The input comes from the keyboard and should (but might not) consist solely of the delmiters (, ), [, ], {, and } separated by whitespace. The output of the program must include following: OK Opener/closer mismatch Missing closer Missing opener Unexpected symbol The name of your class should be ParenChecker. For example, if the input was: ( [ { } ] ) the program should produce the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT