Question Details

[answered] Assignment 4 CS141 - Computer Programming II Chapter 15 - I


Assignment 4 worth 5 points (50/10). Due on Saturday 10/12/2016.? Will deduct 1 point for each day late. Copying each other work will result in giving 0 to both.

The first Question Q1. Will require you to submit your program as .java file that can be run.

The rest of the questions can be answerd as word document file


Assignment 4

 

CS141 ? Computer Programming II

 

Chapter 15 ? Intro. to Data Structure

 

Assignment 4 worth 5 points (50/10). Due on Saturday

 

10/12/2016. Will deduct 1 point for each day late. Copying

 

each other work will result in giving 0 to both.

 

The first Question Q1. Will require you to submit your program

 

as .java file that can be run.

 

The rest of the questions can be answerd as word document

 

file. Please use the following way to name your file:

 

Your answer file name as: StudentId_CS141_Assignment04, where StudentId is

 

your student id

 

Q1. Write the java code to create a linked list of string type.

 

Then, apply the following operations using the library and the

 

available functions:

 

[10 points]

 

1. Add the following node in the same order: ?Ali?, ?Sara?,

 

?Omar?, ?Eman?

 

2. Add at the beginning the node ?Ahmad?

 

3. Print the whole list

 

4. Add the node ?Heba? between node ?Ali? and node

 

?Sara? using iterator

 

5. Remove the last node

 

6. Re-print the whole list

 

Here is the expected output of the program

 

OUTPUT Q2. In the ListIterator class, what is the difference between

 

next() and hasNext() methods?

 

[5 points] Q3. (a) What does the Linked List library Iterator method

 

set() do? (b) And write just one line of java code just to call

 

the set method given the following:

 

[5

 

points]

 

We have a linked list of Student class called students each

 

node in this linked list is an object of type Student. And List

 

Iterator called stdIter pointing to the first node as given by the

 

following code:

 

LinkedList <Student> students = new LinkedList <Student> ();

 

ListIterator <Student> stdIter = students.listIterator();

 

stdIter.next();

 

iterator once // move the Student std1 = new Student();

 

Student object called std1 // construct a new Now write the one line code to call the set()method on the

 

iterator passing it the new object.: Q4. Part(a) show the output for the following code the uses a Queue:

 

[5 points] 1 import java.util.*; 2 public class QueueDemo { 3 4 public static void main(String args) { 5 6 Queue queue = new LinkedList(); 7 8 //add elements to queue using add method 9 10 queue.add("Ali");

 

11 queue.add("Khaled");

 

12 queue.add("Ahmed");

 

13 queue.add("Fares");

 

14 queue.add("Nasser");

 

15 16 System.out.println("Items in the queue..." + queue);

 

17 18 System.out.println("remove element: " + queue.remove() );

 

19 20 System.out.println("retrieve element: " + queue.peek() );

 

21 22 queue.add("Jameel");

 

23 24 System.out.println("remove element: " + queue.remove());

 

25 26 System.out.println("Items in the queue..." 27 + queue.toString());

 

28 } Q4. Part(b) show the output for the following code the uses a Stack:

 

[5 points] 1 import java.util.*; 2 public class StackDemo { 3 4 public static void main(String args) { 5 6 Stack s = new Stack(); 7 8 //add elements to queue using add method 9 10 s.push("Ali");

 

11 s.push("Khaled");

 

12 s.push("Ahmed");

 

13 s.push("Fares");

 

14 s.push("Nasser");

 

15 16 System.out.println("Items in the stack..." + s);

 

17 18 System.out.println("remove element: " + s.pop() );

 

19 20 System.out.println("retrieve element: " + s.peek() );

 

21 22 s.push("Jameel");

 

23 24 System.out.println("remove element: " + s.pop());

 

25 26 System.out.println("Items in the stack..." +

 

27 s.toString() );

 

28 }

 

29 } Q5. Read about the following real life situations and decide

 

whether you will use a stack or a queue. Provide valid reason

 

of your choice.

 

[10

 

points]

 

1)

 

2)

 

3)

 

4)

 

5) A car wash facility.

 

Batteries in Flashlight.

 

Pringles (pack of chips).

 

Customers at Al-Baik.

 

Execution of a recursive method.

 


Solution details:
STATUS
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Sep 18, 2020

PRICE: $15

Solution~0001005030.zip (25.37 KB)

Buy this answer for only: $15

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 18, 2020

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.

Order Now