Question

In: Computer Science

which question is incomplete these question given like they are and i have to answer them....

which question is incomplete these question given like they are and i have to answer them. These are Java questions.

Q1. //Write an iterative method to count long book in the linked list. Assume that book has               method

// Boolean isLong () that returns true if book is long and returns false otherwise.

Public int countLongBooks ()

{

Q2. //Recursive method to add a new node (with myBook as data) at the rear of the list

Public void addToRearRec(Book myBook, Node first)

Q3. //Recursive method returns longest Book in the non-empty linked list. First refers to the first node in the linked l

// list.

    Public Book longestBook ( Node first)

{

Q4. Determine the outcome of the following code if NumberFormatException happened within the try block.

Try

{

    //some code

}

Catch (Number FormatException e)

{

      System.out.println(“Example ne”);

}

Catch (stringIndexOutOfBoundsException e)

{

      System.out.println(“Example two”);

}

Finally

{

       System.out.println(“Finally is dine”);

}

System.out.println(“The next”);

Q5. Determine the outcome of m(4) invocation?

Public void m(int n)

{

If. (n <= 1

System.out.print(“A”);

Else

{

       m(n-1);

       m(n-2);

}

}

Q 6.  

Write “C” next the statements that are correct?

a). Interface is java class that cannot be instantiated.

b). Interface is java class containing constants / or abstract methods.

c). Interface is an abstract class.

d). Interface is java structure containing constants and / or abstract methods.

Q7. Complete code for recursive method which returns shortest person in the nonempty list.Assume that only first n elements in the list have been assigned their values.person class has method getHight().

Public person shortestPersonRec(Person[] list, int n)

{

Solutions

Expert Solution

In Question 1, Write an iterative method to count long book in the linked list, it is mentioned that assume that book has method Boolean isLong () that returns true if book is long and returns false otherwise. But in the example method it is given like this

Public int countLongBooks ()

{

in which firstly, alphabet 'p' of public is written in upper case which is wrong and the same mistake is in all other questions, secondly, it was mentioned previously that the method should be isLong() with return type boolean but the method name in example given is countLongBooks() with return type int. This may create confusion.

In Question 2, Recursive method to add a new node (with myBook as data) at the rear of the list

Public void addToRearRec(Book myBook, Node first), it is mentioned that the new node should be added with myBook as data. Now in linear linked list each node always contains two section 1) Info / data part and 2) Next address part. There cannot be a node in linked list with only data part. But if it was asked to create a new node object as data then it is correct.

In Question 3,  Recursive method returns longest Book in the non-empty linked list. First refers to the first node in the linked list, Public Book longestBook ( Node first){

There is no problem with this question. The question is clear and complete.

In Question 4,

Determine the outcome of the following code if NumberFormatException happened within the try block.

Try

{

    //some code

}

Catch (Number FormatException e)

{

      System.out.println(“Example ne”);

}

Catch (stringIndexOutOfBoundsException e)

{

      System.out.println(“Example two”);

}

Finally

{

       System.out.println(“Finally is dine”);

}

System.out.println(“The next”);

It was asked to determine whether NumberFormatException will occur in the try block or not but no code is written inside the try block. Exceptions occurs at runtime when the user enters any incorrect input at runtime. Therefore, Question - 4 is incomplete. Moreover, lot of syntax error is there in the code snippet like  try, catch finally should be written in lower case and instead of class name stringOutOfBoundException, it should be ArrayIndexOutOfBoundsException.

Question 5 and 6 is also ok only few syntax errors are there.


Related Solutions

STEVEJ DO NOT ANSWER MY QUESTIONS. YOU HAVE SUBMITTED INCOMPLETE QUESTIONS. IF YOU ANSWER THESE I...
STEVEJ DO NOT ANSWER MY QUESTIONS. YOU HAVE SUBMITTED INCOMPLETE QUESTIONS. IF YOU ANSWER THESE I WILL REPORT YOU TO CHEGG. From the economic way of thinking 2 part questions: Fiat money is something that: A Becomes money only by general consensus B the political authority officially claims it as money C does not exist in the US D traders find unacceptable in highly developed economic systems Inflation in the United States, other things constant, A depreciates the value of...
given the following questions, i would like to ... Question Given the following questions, I would...
given the following questions, i would like to ... Question Given the following questions, I would like to know the answers to c, d, and e. located at the bottom (due to 4 answers per post limit). Thanks! Platinum (Pt) is used in part of your car's catalytic converter to reduce carbon monoxide emissions by the following chemical reaction: 2CO(g) + O2(g) Pt 2CO2(g) ---> 1) A matrix contains 7.1mg Pt/g of matrix. What is the %Pt in the matrix...
This has to have in-text citations and reference for me to like the answer or I...
This has to have in-text citations and reference for me to like the answer or I won't accept it Question: Write 2-3 paragraphs on the Baddeley-Hitch model. You are required to cite a source.&n... write 2-3 paragraphs on the Baddeley-Hitch model. You are required to cite a source. This means you need the in-text citation within your paragraph and the full reference at the end of your paragraphs. Please note that 40% of your grade for this assignment is based...
Answer the following question and I would like you to provide me with references that is...
Answer the following question and I would like you to provide me with references that is not older than 5 years old please for each please Question 1 A pediatric patient has just been diagnosed with otitis externa. Which of the following should the patient be instructed to do? Use alcohol drops before swimming Wear earplugs at all times with swimming Limit swimming for the remainder of summer Keep ear dry until symptoms improve Question 2 The nurse practitioner is...
I have a question that I would like an explanation on how an ethical hacker uses...
I have a question that I would like an explanation on how an ethical hacker uses the information derived by use of Nslookup and Whois to mitigate network connectivity issues. If you could explain in a paragraph it would help me tremendously.
(Please answer with new unique words using keyboard, and sure I will like your answer) Question...
(Please answer with new unique words using keyboard, and sure I will like your answer) Question 1: Discuss how venture capitalists reduce their risk when investing in startup businesses. Justify your answer citing appropriate examples from Saudi Firms.
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With...
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With the aid of supply and demand diagrams, explain how each of the following would likely affect the prices and quantities of cigarettes sold in the US. (a) A cure is found for lung cancer. (b) There is a substantial increase in wages in tobacco growing states. (c) A fertilizer that increases the yield per acre of tobacco is discovered. (d) There is a substantial...
Please I need answer for This question I have assignment for this subjects . Please be...
Please I need answer for This question I have assignment for this subjects . Please be brief and to the point . Write than 3 pages (maximum),but It is enough to give the name of the authors Only legible answers will be considered.Thanks in advance/Ha !-What are Structural discrimination in the housing market in Sweden?.Give an overview of the theories of discrimination used in economics. What are the main differences between these theories?
Please I need answer for This question I have assignment for this subjects . Please be...
Please I need answer for This question I have assignment for this subjects . Please be brief and to the point . Write than 3 pages (maximum),but It is enough to give the name of the authors Only legible answers will be considered.Thanks in advance/Ha 1-Discrimination in the Swedish housing market ?Give an overview of the theories of discrimination used in economics. What are the main differences between these theories?
Please I need answer for This question I have assignment for this subjects . Please be...
Please I need answer for This question I have assignment for this subjects . Please be brief and to the point . ,but It is enough to give the name of the authors Only legible answers will be considered.Thanks in advance/Ha 1- Give an overview of the Becker theory of Discrimination. a-Discrimination definition. b-Explicit Discrimination . c-Hypothesis formulation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT