Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Practice Questions 1. Explain the peration of the code below . private void upda

ID: 3593680 • Letter: P

Question

Practice Questions 1. Explain the peration of the code below . private void updateDisplay) int hour-hours getvalue)i String suffix am" if (hoUr>-12) hourhour-12 hour 12 displaystring hour +""minutes getDisplayvalue+ suteix 2. Write a Java statements that define a variable named window of type Rectangle. and then areate aRectangle objeet and assign it to that variable.The Rectangle constructor has two int pa rameters 3 I a collection stores 10 objects.what value would be returned from a call to its size method? 4 What is the index ot the lastitem stored in a colleetion of 15 objeets? 5 Suppose that an objeet is stored at index 6 in a collection.What will be its index after the objeets at index o and index 9 are removed?

Explanation / Answer

Hello there,

1) this is a private method, which returns nothing.

* In the first line it gets the hour by hours.getValue(), then it defines a string suffix as default value 'am'.

* After that, it has if condition, which check if hour is more than 12, then minus the 12 from hour and change suffix value 'pm' from 'am'.

* Then, in the next check, if hour is equal to 0 then make hour = 12.

* In the last line it has display string as time,i.e. hours.minutes {am or pm} ; it gets minutes by minutes.getDisplayValue.

2) Rectangle window = new Rectangle(int a, int b);

Here, window is variable of type Rectangle and we are creating object of Rectangle by calling constructor of it by new keyword as new Rectangle(int a, int b).

3) If a collection stores 10 objects, its size function call will return value 10 as answer, because it returns the element inside the collection.

4) As indexes starts from 0 in collection and total elements are 15, then index of last item stored will be '14'.

5) An object stored at index 6, and if item at index 9 will be removed then it will not affect index 6 item, but when index 0 item will be removed then it will decrease its index by one, so now index 6 item's new index will be 5.

Hope, you got your answers, feel free to ask any queries and to give feedback.

Thank you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote