Information Technology

I have an assignment it is due after 4 hoursThanks
lab10_10.doc

Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Essay on
Information Technology
Just from $13/Page
Order Essay

Chapter 10, ArrayList
1. Write a method markLength4 that takes an ArrayList of Strings as a parameter and that places a String of four
asterisks (“****”) in front of every String of length 4. For example, suppose that an ArrayList called “list”
contains the following values:
(this, is, lots, of, fun, for, every, Java, programmer)
And you make the following call:
markLength4(list);
Then list should store the following values after the call:
(****, this, is, ****, lots, of, fun, for, every, ****, Java, programmer)
Notice that you leave the original Strings in the list (this, lots, Java) but include the four-asterisk String in front of
each to mark it. You may assume that the ArrayList contains only String values, but it might be empty.
1 of 4
2. Write a method manyStrings that takes an ArrayList of Strings and an integer n as parameters and that replaces
every String in the original list with n of that String. For example, suppose that an ArrayList called “list” contains
the following values:
(“squid”, “octopus”)
And you make the following call:
manyStrings(list, 2);
Then list should store the following values after the call:
(“squid”, “squid”, “octopus”, “octopus”)
As another example, suppose that list contains the following:
(“a”, “a”, “b”, “c”)
and you make the following call:
manyStrings(list, 3);
Then list should store the following values after the call:
(“a”, “a”, “a”, “a”, “a”, “a”, “b”, “b”, “b”, “c”, “c”, “c”)
You may assume that the ArrayList you are passed contains only Strings and that the integer n is greater than 0.
2 of 4
Chapter 12, Recursion
3. Write a RECURSIVE method called “sequence” that takes a single int parameter (n) and returns the int value of
the nth element of the sequence S = 2, 4, 6, 12, 22, 40, 74, 136, 250, 460, …
Where S is defined by the recursive formula:
For n >= 0
S(0) = 2; // Base case 1
S(1) = 4; // Base case 2
S(2) = 6; // Base case 3
S(N) = 2 * ( S(N-1)/2 + S(N-2)/2 + S(N-3)/2)
4. Given the sequence, S2 = 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, …
Write a RECURSIVE method called “sequence2” that takes a single int parameter (n) and returns the int value of the
nth element of the sequence S2. You will need to determine any base cases and a recursive case that describes the
listed sequence.
Use the following code to test your answers to questions 3 and 4
the output should print the two sequences given (S & S2):
public class TestSequences {
public static void main(String[] args) {
for(int i = 0; i < 10; i++) { System.out.print(sequence(i) + " "); } System.out.println(); for(int i = 0; i < 10; i++) { System.out.print(sequence2(i) + " } // 2, 4, 6, 12, 22, 40, 74, 136, 250, 460 "); // 1, 2, 4, 5, 7, 8, 10, 11, 13, 14 } // *** Your method for sequence here // *** Your method for sequences2 here *** *** } // end of TestSequences class 3 of 4 5. For the TimeSpan class described below, add a compareTo method that takes another TimeSpan object as a parameter & returns: -1 if this TimeSpan is SMALLER than to the TimeSpan object passed in as a parameter 0 if both TimeSpans are the same 1 if this TimeSpan is GREATER than the TimeSpan object passed in as a parameter Add code, as needed, to allow the Collections class to sort the ArrayList of TimeSpan objects import java.util.*; public class TimeSpan implements { private int hours; private int minutes; public TimeSpan(int hours1, int minutes1) { hours = 0; minutes = 0; add(hours1, minutes1); } public void add(int hours1, int minutes1) { hours += hours1; minutes += minutes1; while (minutes > 60) {
minutes -= 60;
// convert 60 min –> 1 hour
hours++;
}
}
public void add(TimeSpan time) {
add(time.hours, time.minutes);
}
public double getTotalHours() {
return hours + minutes / 60.0;
}
public String toString() {
return hours + “h-” + minutes + “m”;
}
//
*** Your method code here ***
public static void main(String[] args) {
TimeSpan t1 = new TimeSpan(4, 13);
TimeSpan t2 = new TimeSpan(5, 8);
TimeSpan t3 = new TimeSpan(3, 51);
TimeSpan t4 = new TimeSpan(6, 76);
TimeSpan t5 = new TimeSpan(1, 1);
ArrayList list = new ArrayList();
list.add(t1);
list.add(t2);
list.add(t3);
list.add(t4);
list.add(t5);
System.out.println(list);
Collections.sort(list);
System.out.println(list);
}
}
Expected Output:
> run TimeSpan
[4h-13m, 5h-8m, 3h-51m, 7h-16m, 1h-1m]
[1h-1m, 3h-51m, 4h-13m, 5h-8m, 7h-16m]
4 of 4

Purchase answer to see full
attachment

GradeAcers
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

Order your essay today and save 15% with the discount code DISCOUNT15