Question

In: Computer Science

I am not quite sure how to get this program working or how to start it...

I am not quite sure how to get this program working or how to start it in the first place.

Write a full Java program and do the following:

1- Create a generic class and declare a one dim array as a private member.

2- Add a constructor to initialize the array.

3- A set method to set the array.

4- Sort method to sort the array.

5- Print method to print the array.

6- Reverse method to reverse the array recursively.

Solutions

Expert Solution

// ArrayOperation.java : Java program to create a generic class that consists of types that are comparable (for sorting)

public class ArrayOperation<T extends Comparable<T>> {

      

       private T array[];

      

       // constructor that initializes the array to input argument inArray

       public ArrayOperation(T inArray[])

       {

             array = (T[])new Comparable[inArray.length];

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

                    array[i] = inArray[i];

       }

      

       // method to the array to inArray

       public void set(T inArray[])

       {

             array = (T[])new Object[inArray.length];

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

                    array[i] = inArray[i];

       }

      

       // method to sort the elements of array

       public void sort()

       {

             int min;

             for(int i=0;i<array.length-1;i++)

             {

                    min = i;

                   

                    for(int j=i+1;j<array.length;j++)

                    {

                           if(array[j].compareTo(array[min]) < 0)

                                 min = j;

                    }

                   

                    if(i != min)

                    {

                           T temp = array[i];

                           array[i] = array[min];

                           array[min] = temp;

                    }

             }

       }

      

       // method to display the array

       public void show()

       {

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

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

       }

      

       // method to reverse the array

       public void reverse()

       {

             for(int i=0,j=array.length-1;i<array.length/2;i++,j--)

             {

                    T temp = array[i];

                    array[i] = array[j];

                    array[j] = temp;

             }

       }

      

       public static void main( String[] args)

       {

             // test the class methods

             Integer array[] = {21,15,20,12,7,10,6,5,17};

             ArrayOperation<Integer> obj = new ArrayOperation<>(array);

             System.out.println("Initial array : ");

             obj.show();

             obj.sort();

             System.out.println("Sorted array : ");

             obj.show();

             System.out.println("Reversed array : ");

             obj.reverse();

             obj.show();

            

       }

}

//end of program

Output:


Related Solutions

I am not quite sure what this question is asking, nor do I understand how to...
I am not quite sure what this question is asking, nor do I understand how to apply the lower-of-cost-or-NRV. The controller of Alt Company is applying the lower-of-cost-or-net realizable value basis of valuing its ending inventory. The following information is available: Cost Net Realizable Value Lawnmowers: Self-propelled $14,800 $17,000 Push type 19,000 18,000 Total 33,800 35,000 Snowblowers: Manual 29,800 31,000 Self-start 19,000 21,000 Total 48,800 52,000 Total inventory $82,600 $87,000 Compute the value of the ending inventory by applying the...
I am working on this problem for the company AT & T and am not sure...
I am working on this problem for the company AT & T and am not sure how to start it. Draw a chart of the main inter-organizational linkage mechanisms (e.g., long -term contacts, strategic alliances, mergers) that your organization uses to manage its symbiotic resource interdependencies. Using resource dependence theory and transaction cost theory, discuss why the organization to manage its interdependencies in this way. Do you think the organization has selected the most appropriate linkage mechanisms? Why or why...
Hi! I am working on a lab for Organic Chemistry and I want to make sure...
Hi! I am working on a lab for Organic Chemistry and I want to make sure my answers are correct before submitting it! Thank you in advance! Stereoisomerism: A Model Exercise In this experiment you will construct models with your molecular model set that illustrate the concepts of chirality, chiral center (stereogenic center, asymmetric carbon atom), enantiomers, diastereomers, and meso forms. You will also learn about two conventions, R-S and Fischer, for designating the configurations of chiral molecules. You will...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
I have homework on this but I am not sure how to solve it and which...
I have homework on this but I am not sure how to solve it and which formula to use in excel, can u please help me Rebecca is considering buying a 2019 Genesis G70 costing $37,900 and finds that the retaining values of the vehicle over the next four years are as follows: Percent of the total value retained after 24 months: 71% Percent of the total value retained after 48 months: 53% If her interest rate is 5% compounded...
I am stuck on this problem and I am not sure what the solution is. In...
I am stuck on this problem and I am not sure what the solution is. In C Write item.h and item.c. In item.h, typedef a struct (of type t_item) which contains the following information: t_item: char name[MAX_ITEM_NAME_STRING]; char description[MAX_ITEM_DESCRIPTION_STRING]; Make sure that MAX_ITEM_NAME_STRING and MAX_ITEM_DESCRIPTION_STRING are defined with suitable sizes in your item.h. Typical values are, 25 and 80, respectively. Add the following interface definition to item.h: int item_load_items(t_item items[], int max_items, char *filename); Returns the number of objects loaded...
I am working on a C++ program, where a user puts in a notation a playing...
I am working on a C++ program, where a user puts in a notation a playing card and the output is the full name of the card.(ex: KH = King of Hearts) I have most of it working but I want to have an error come up when the user puts in the wrong info and then loop back to the original question. Am I setting it up wrong? Pasted below is my code #include<iostream> #include<string> using namespace std; int...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am not sure how to approach this. You are managing a bake sale for a...
I am not sure how to approach this. You are managing a bake sale for a club at your school. It’s being held each weekend in the fall that the football team has a home game. This year, there will be five home games. The club sells cookies in packages of two dozen. The selling price per package is $8.65. The packaging material costs $.11 (11 cents) per package. You pay the regular kitchen staff a direct labor cost for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT