In a class named ArrayMethods, write each of the methods described below. 0. Include the following class
Fantastic news! We've Found the answer you've been seeking!
Question:
In a class named ArrayMethods, write each of the methods described below.
Transcribed Image Text:
0. Include the following class declaration at the beginning of your class: public static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday, "Friday", This array, declared at the class level, is a static final array of strings. Each element of this array reprsents a day of the week. Declaring this array static means it has class level scope and can be accessed by any method written in this class. We will only be using it in one of the methods. Declaring this array to be final means it is read only and cannot be modified. By convention, variables declared to be constant variables (i.e. final) are typically always in upper case. This way when you are looking through code and see a variable in all upper case, you should be able to assume that the variable is read only. 1. Write a method with the header public static void swap Adjacent (int [] values) that takes a reference to an array of integers values and swaps adjacent pairs of elements: values [0] with values [1], values [2] with values [3], etc. For example, after implementing this method and compiling your Array Methods class, you should see the following when you test the method programmatically: int[] a1 = {0, 2, 4, 6, 8, 10}; ArrayMethods. swapAdjacent(a1); System.out.println( Arrays.toString(a1) ); should output: [2, 0, 6, 4, 10, 8] In an odd-length array, the last element should not be moved: 0. Include the following class declaration at the beginning of your class: public static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday, "Friday", This array, declared at the class level, is a static final array of strings. Each element of this array reprsents a day of the week. Declaring this array static means it has class level scope and can be accessed by any method written in this class. We will only be using it in one of the methods. Declaring this array to be final means it is read only and cannot be modified. By convention, variables declared to be constant variables (i.e. final) are typically always in upper case. This way when you are looking through code and see a variable in all upper case, you should be able to assume that the variable is read only. 1. Write a method with the header public static void swap Adjacent (int [] values) that takes a reference to an array of integers values and swaps adjacent pairs of elements: values [0] with values [1], values [2] with values [3], etc. For example, after implementing this method and compiling your Array Methods class, you should see the following when you test the method programmatically: int[] a1 = {0, 2, 4, 6, 8, 10}; ArrayMethods. swapAdjacent(a1); System.out.println( Arrays.toString(a1) ); should output: [2, 0, 6, 4, 10, 8] In an odd-length array, the last element should not be moved:
Expert Answer:
Answer rating: 100% (QA)
Create a class named ArrayMethods in which the implementation of different methods is to be done public class ArrayMethods public static final String DAYS Sunday Monday Tuesday Wednesday Thursday Frid... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
At December 31, 2010, Cafu Co. reported the following information on its statement on financial position. Accounts receivable...............R$960,000 Less: Allowance for doubtful accounts............
-
What are the amounts of inventory reported by Coca-Cola and PepsiCo at end of 2006 respectively? What percent of total assets is invested in inventory by each company?
-
This problem uses the demand information given in Problem 1. Each game owner buys an average of 10 video games. You earn $10 profit per video game. What price should you charge for the game console?...
-
Founded in 1966 as a trader of oil and oil products, Vitol is a company with no external shareholders. All shareholders are also employees. It is a conglomerate company of energy companies that work...
-
In its annual report to stockholders, Hakobe Inc. presents a condensed balance sheet with detailed data provided in supplementary schedules. 1. From the adjusted trial balance of Hakobe, prepare the...
-
15. You are provided with cost data for the Amber Amazing Restaurant for its signature dinner dish that it offers to its patrons. Use the following figure for this business to answer the questions...
-
Janice Morgan, age 24, is single and has no dependents. She is a freelance writer. In January 2021, Janice opened her own office located at 2751 Waldham Road, Pleasant Hill, NM 88135. She called her...
-
Apply your understanding of industrial/organizational psychology to a specific job and organization. This paper should be an objective analysis of a specific job in a particular work organization. It...
-
We know that the speed of sound depends on the density of the particles of the medium, so how come that the speed of sound in Aluminum ( density 2 7 0 0 kg / m 3 ) is higher than in lead ( density 1...
-
1 mole of air ( assume: ideal diatomic gas ) at 3 0 0 K is placed in a cylinder closed by a heavy piston up to a volume of 5 ml . Calculate the final volume of the gas when 4 . 4 0 kJ of energy in...
-
Crane Company's year end is July 31. Crane prepares adjusting entries to accrue interest revenue annually. On June 30, the Notes Receivable account balance is $24,200 and the Credit Card Receivable...
-
Unit Testing Run the Unit Test program, GradeCalculatorTest, as shown above. Add the required tests to GradeCalculatorTest.java, recompile, and rerun it. Again, if you are doing a good job...
-
A stick of length ( L ) and mass ( M ) lies on a frictionless horizontal table. A sharp impulse ( J ) is perpendicularly applied at one of the ends. Just after the impulse, what is the velocity of...
-
You were able to obtain the following from the accountant for Agdangan Corp. related to the companys liabilities as of December 31, 2007. Accounts payable P650,000 Notes payable trade 190,000 Notes...
-
The company manufactures three products: wooden chairs, tables and dressers. AFC started off as a 'Mom & Pop' shop but has grown rapidly. AFC uses one assembly line to build all three products,...
-
Which Java statement produces w on one line and xyz on the next line? a. System.out.println(wxyz); b. System.out.println(w + xyz); c. System.out.println(w xyz); d. System.out.println(w x y z);
-
a. Sammys Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapter 2, you wrote an application that prompts the user for the number of...
-
a. Write an application that accepts up to 20 Strings, or fewer if the user enters a terminating value. Store each String in one of two listsone list for short Strings that are 10 characters or fewer...
-
______________ occur(s) when the speaker should pause but instead fills the silence (umm, ahh).
-
Identify an election (federal, state, or local) for which a debate was broadcast. Analyze how the different speakers were able to adapt their messages based on the moderators questions and their...
-
___________ refers to your credibility as a presenter as well as the credibility of the information delivered in your presentation.
Study smarter with the SolutionInn App