What order? (function templates) Define a generic function called CheckOrder() that checks if four items are in ascending, neither, or descending order. The function should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order. The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, strings, characters, or doubles. Ex. If the input is:

Answers

Answer 1

Answer:

Explanation:

The following code was written in Java and creates the generic class to allow you to compare any type of data structure. Three different test cases were used using both integers and strings. The first is an ascending list of integers, the second is a descending list of integers, and the third is an unordered list of strings. The output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Order: " + checkOrder(10, 22, 51, 53));

       System.out.println("Order: " + checkOrder(55, 44, 33, 22));

       System.out.println("Order: " + checkOrder("John", " Gabriel", "Daniela", "Zendaya"));

   }

   public static <E extends Comparable<E>> int checkOrder(E var1, E var2, E var3, E var4) {

       E prevVar = var1;

       if (var2.compareTo(prevVar) > 0) {

           prevVar = var2;

       } else {

           if (var3.compareTo(prevVar) < 0) {

               prevVar = var3;

           } else {

               return 0;

           }

           if (var4.compareTo(prevVar) < 0) {

               return 1;

           }  else {

               return 0;

           }

       }

       if (var3.compareTo(prevVar) > 0) {

           prevVar = var3;

       }

       if (var4.compareTo(prevVar) > 0) {

           return -1;

       }

       return 0;

   }

}

What Order? (function Templates) Define A Generic Function Called CheckOrder() That Checks If Four Items

Related Questions

hub stake should always be provided with a lath stake so that the information about what the hub represents can be written on the lath stake True False

Answers

Answer:

True

Explanation:

To protect them from becoming disturbed by construction operations, hub stakes are placed on both sides of a roadway at a certain distance outside the work zone. The final stakes are connected to the hub stakes, which are used to write the essential information.

As a result, hub stakes are always accompanied with stakes.

Other Questions
Swifty Corporation purchased a truck at the beginning of 2020 for $109600. The truck is estimated to have a salvage value of $4100 and a useful life of 123000 miles. It was driven 18000 miles in 2020 and 26000 miles in 2021. What is the depreciation expense for 2020?a. $37752 b. $22308 c. $16639 d. $15444 What is the highest peak in North America? A. Mt. Saint Helen B. Mt. McKinley C. Mt. Whitney D. Mt. Rainier Please select the best answer from the choices provided A B C D "Why Do We Study the Sun?" How does the Sun help to protect life on Earth? what is the range of the funcion y=x^2 Figure A is a scale image of Figure B. What is the value of x?khan academy 9. Mariah has 28 centimeters of reedand 10 meters of reed for weavingbaskets. How many meters of reeddoes she have? Write your answer as adecimal and explain your answer. Explain, In your own words, why the therapeutic alliance is so important in confronting offenders. Team members Corinne, Kevin, and Tomas decide to share the costof 2 motor controllers and 4 wheels equally. How much does eachmember need to contribute?Please help(write step by step and upload pic or do it here please I appreciate it so much ! ntitative reasoning 3ples603903601533612315235-8H 24 24 180106030 A clnica odontolgica Dentes Felizes calcula o valor de seus atendimentos a partir de uma taxa fixa de R$ 100,00 e R$ 60,00 por cada obturao. Tenant Tomas and landlord Landis enter into a contract for Tomas to rent Landis's home for two years. Halfway through the lease, Tomas decides to install smart lights and a security system that requires intensive modifications to the wiring and electrical system. May Tomas make such improvements? I will mark you brainlist if you helppp me pls and thankyouuu help pls and explain!!!If x^2 + kx + 6 = (x+n)(x + 3) for all values of x, where k and n are constants, what is the value of k?A) 5B) 3C) 2D) 1 1 ________ does Polly doin the evening?___________________2 ________ phone isringing now?___________________really fast5 ________ does thepostman bring you theletter?___________________6 ________ does Danielride his scooter?___________________9 ________ does Monawork?___________________10 ________ does Tomcan see fish?___________________ A large container holds 4 gallons of chocolate milk that has to be poured into bottles. Each bottle holds 2 pints.If the ratio of gallons to pints is 1: 8, bottles are required to hold the 4 gallons of milk. The Aqua Liquid Assets Money Market Mutual Fund has a NAV of $1 per share. During the year, the assets held by this fund appreciated by 1.4 percent. If you had invested $50,000 in this fund at the start of the year, how many shares would you own at the end of the year Read this passage I am mindful that only yesterday in Birmingham, Alabama, our children, crying out for brotherhood, were answered with fire hoses, snarling dogs and even death. I am mindful that only yesterday in Philadelphia, Mississippi, young people seeking to secure the right to vote were brutalized and murdered. And only yesterday more than 40 houses of worship in the State of Mississippi alone were bombed or burned because they offered a sanctuary to those who would not accept segregation. I am mindful that debilitating and grinding poverty afflicts my people and chains them to the lowest rung of the economic ladder. -Martin Luther King Jr., Nobel Prize acceptance speech, 1964 How does King show that the struggle for freedom and equality is not over? A. By asking the committee to help thestop the violence B. By refusing the award because peace has not been achieved C. By giving examples of violent events that recently took place D. By explaining that he is not an expert in the field of civil rights A town recently dismissed 5 employees in order to meet their new budget reductions. The town had 4 employees over 50 years of age and 16 under 50. If the dismissed employees were selected at random, what is the probability that no more than 1 employee was over 50 You are analyzing ABC Company, a computer manufacturer. You notice that inventory turnover this year is significantly lower than in prior years. You also notice that accounts receivable turnover is significantly lower this year when compared to previous years. Provide three explanations that would be consistent with your observation for inventory turnover and include an explanation of whether these would be of concern to you, as well as what the effect might be on the next period's financial results. In addition, provide three explanations that would be consistent with your observation of the accounts receivable turnover, and explain whether these would be of concern to you. When people are asked to recall a list of words they had earlier memorized, they often substitute common synonyms for some of the words on the original list. This best illustrates the effects of