Java programming homework: Method #1: Write a method named swapPairs that accepts an array of strings as a parameter and switches the order of values in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on. For example, if the array initially stores these values: String[] a = {"four", "score", "and", "seven", "years", "ago"}; swapPairs(a); Your method should switch the first pair ("four", "score"), the second pair ("and", "seven") and the third pair ("years", "ago"), to yield this array: {"score", "four", "seven", "and", "ago", "years"} If there are an odd number of values, the final element is not moved. For example, if the original list had been: {"to", "be", "or", "not", "to", "be", "hamlet"} It would again switch pairs of values, but the final value ("hamlet") would not be moved, yielding this list: {"be", "to", "not", "or", "be", "to", "hamlet"} Method #2: Write a method named longestSortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array. For example, if a variable named array stores the following values: int[] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12}; then the call of longestSortedSequence(array) should return 4 because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207). Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the array stores the following values: int[] array2 = {17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19} Then the method would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8). Your method should return 0 if passed an empty array. - Your code should have two classes ( Drive , Methods ) - Methods class should include longestSortedSequence(array) and swapPairs(array) methods - Drive class should have : 1. Main method 2. One object of class Methods ( object_one ) 3. Test longestSortedSequence(array) and swapPairs(array) method by object_one object - longestSortedSequence(array) and swapPairs(array) methods can accept an array with any different length - you can deliver your code by moodle assignment #1 - your code should be fully commented - copy the classes ( Drive , Methods ) from src file from your project file then submit it Notes:  - you should be ready to discuss your code by the first lecture after assignment due date - deadline for submitting your code is 03/03/2021 – 11:59pm - all copies from your classmates or internet will be evaluated by ZER

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java programming homework:

Method #1:

Write a method named swapPairs that accepts an array of strings as a parameter and switches the order of values in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on. For example, if the array initially stores these values:

String[] a = {"four", "score", "and", "seven", "years", "ago"}; swapPairs(a);

Your method should switch the first pair ("four", "score"), the second pair ("and", "seven") and the third pair ("years", "ago"), to yield this array:

{"score", "four", "seven", "and", "ago", "years"}

If there are an odd number of values, the final element is not moved. For example, if the original list had been:

{"to", "be", "or", "not", "to", "be", "hamlet"}

It would again switch pairs of values, but the final value ("hamlet") would not be moved, yielding this list:

{"be", "to", "not", "or", "be", "to", "hamlet"}

Method #2:

Write a method named longestSortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array. For example, if a variable named array stores the following values:

int[] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12};

then the call of longestSortedSequence(array) should return 4 because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207). Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the array stores the following values:

int[] array2 = {17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19}

Then the method would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8). Your method should return 0 if passed an empty array.

- Your code should have two classes ( Drive , Methods )

- Methods class should include longestSortedSequence(array) and swapPairs(array) methods - Drive class should have :

1. Main method

2. One object of class Methods ( object_one )

3. Test longestSortedSequence(array) and swapPairs(array) method by object_one object

- longestSortedSequence(array) and swapPairs(array) methods can accept an array with any different length

- you can deliver your code by moodle assignment #1

- your code should be fully commented

- copy the classes ( Drive , Methods ) from src file from your project file then submit it

Notes:

 - you should be ready to discuss your code by the first lecture after assignment due

date

- deadline for submitting your code is 03/03/2021 – 11:59pm

- all copies from your classmates or internet will be evaluated by ZERO

 

 

ASSIGNMENT #1
CSCI 1106 – PROGRAMMING II
Method #1:
Write a method named swapPairs that accepts an array of strings as a parameter and
switches the order of values in a pairwise fashion. Your method should switch the order
of the first two values, then switch the order of the next two, switch the order of the next
two, and so on. For example, if the array initially stores these values:
String[] a = {"four", "score", "and", "seven", "years", "ago"};
swapPairs(a);
Your method should switch the first pair ("four", "score"), the second pair ("and", "seven") and
the third pair ("years", "ago"), to yield this array:
{"score", "four", "seven", "and", "ago", "years"}
If there are an odd number of values, the final element is not moved. For example, if the
original list had been:
{"to", "be", "or", "not", "to", "be", "hamlet"}
It would again switch pairs of values, but the final value ("hamlet") would not be moved,
yielding this list:
{"be", "to", "not", "or", "be", "to", "hamlet"}
1
Transcribed Image Text:ASSIGNMENT #1 CSCI 1106 – PROGRAMMING II Method #1: Write a method named swapPairs that accepts an array of strings as a parameter and switches the order of values in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on. For example, if the array initially stores these values: String[] a = {"four", "score", "and", "seven", "years", "ago"}; swapPairs(a); Your method should switch the first pair ("four", "score"), the second pair ("and", "seven") and the third pair ("years", "ago"), to yield this array: {"score", "four", "seven", "and", "ago", "years"} If there are an odd number of values, the final element is not moved. For example, if the original list had been: {"to", "be", "or", "not", "to", "be", "hamlet"} It would again switch pairs of values, but the final value ("hamlet") would not be moved, yielding this list: {"be", "to", "not", "or", "be", "to", "hamlet"} 1
Method #2:
Write a method named longestSortedSequence that accepts an array of integers as a
parameter and that returns the length of the longest sorted (nondecreasing) sequence of
integers in the array. For example, if a variable named array stores the following values:
int[] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12};
then the call of longestSortedSequence(array) should return 4 because the longest sorted
sequence in the array has four values in it (the sequence -3, 0, 14, 207). Notice that
sorted means nondecreasing, which means that the sequence could contain duplicates.
For example, if the array stores the following values:
int[] array2 = {17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19}
Then the method would return 5 for the length of the longest sequence (the sequence 3,
5, 5, 5, 8). Your method should return o if passed an empty array.
Requirements:
Your code should have two classes ( Drive , Methods )
Methods class should include longestSortedSequence(array) and swapPairs(array) methods
Drive class should have :
1. Main method
2. One object of class Methods ( object_one )
3. Test longestSortedSequence(array) and swapPairs(array) method by object_one object
longestSortedSequence(array) and swapPairs(array) methods can accept an array with any
different length
you can deliver your code by moodle assignment #1
your code should be fully commented
copy the classes ( Drive , Methods ) from src file from your project file then submit it
Notes:
you should be ready to discuss your code by the first lecture after assignment due
date
deadline for submitting your code is 03/03/2021 – 11:59pm
all copies from your classmates or internet will be evaluated by ZERO
2.
Transcribed Image Text:Method #2: Write a method named longestSortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array. For example, if a variable named array stores the following values: int[] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12}; then the call of longestSortedSequence(array) should return 4 because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207). Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the array stores the following values: int[] array2 = {17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19} Then the method would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8). Your method should return o if passed an empty array. Requirements: Your code should have two classes ( Drive , Methods ) Methods class should include longestSortedSequence(array) and swapPairs(array) methods Drive class should have : 1. Main method 2. One object of class Methods ( object_one ) 3. Test longestSortedSequence(array) and swapPairs(array) method by object_one object longestSortedSequence(array) and swapPairs(array) methods can accept an array with any different length you can deliver your code by moodle assignment #1 your code should be fully commented copy the classes ( Drive , Methods ) from src file from your project file then submit it Notes: you should be ready to discuss your code by the first lecture after assignment due date deadline for submitting your code is 03/03/2021 – 11:59pm all copies from your classmates or internet will be evaluated by ZERO 2.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education