What are the values of these boolean expressions

Assignment Help JAVA Programming
Reference no: EM13212152

1) Give the Big O for the following:

a. n2 + 6n + 32

b. n +6

c. Analyze the code below for integer n:           

while (n > 0) {

   n = n/10; // Integer division

}

2) Explain in your own words - when is it appropriate to implement a static method? Give an example as part of your answer.

Answer: The best time to use a static method would be if a method needs to be in a class, but not  tied to an object: 
Example : class Languages {   public static void main(String[] args) {     display();  
 }     
static void display()      
 {     
System.out.println("Java is my favorite programming language.");   } 
}

3) Consider the following method with integer value x.

                  public static test(int x)

                               {

                               x += 2;

                               }

Suppose y has a value of 10, then the method is activated test(y) what is the value of y after this activation? The Value of Y will be 5.

4) Consider this code that creates some Location objects with coordinates x=10 and y=20:

                  Location a, b, c;

                  a = new Location(10,20);

                  b = new Location(10,20);

                  c = b;

                  ...

After this code executes, what are the values of these boolean expressions?

a) a= =b

b) a.equals(b)

c) a= =c

d) a.equals(c)

e) b= =c

f) b.equals(c)

Also, explain the difference between == and the equals method for the Location class.

5) Write a code fragment (in Java) that creates an array 50 integers, and initializes each cell to the same value as its index number (i.e. [0] = 0, [1] = 1, etc.).  [hint: use a loop]

6) What happens if you call new but the heap is out of memory?

7) Draw a picture of memory after these statements:

    int[ ] m = new int[2];

    m[0] = 0;

    m[1] = 1;

    int[ ] p = m;

    p[0] = 4;

    p[0] = 5

8) Consider the method:

                  public static test2(int[ ] b)

                  {

                               b[0]++;

                  }         

Draw a picture of memory after these statements (also show what is printed out)

                               int[ ] x = new int[100];

                               x[0] = 2;

                               foo(x);

                               System.out.println(x[0]);

9) Describe (in English) the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.

10) Write out the following method as a static method for the IntNode class (similar to the book: use data & link) public static int count10s (IntNode head)

               // Precondition:  Head is a reference to a linked list of integers,

               // condition of the list is unknown (empty or not)

               // Postcondition: Method returns number of 10s found in the linked list.

               // list is unchanged.

11)  Write out the following method as a static method for the IntNode class (similar to the book:  use data & link)

public static void insertAtTail (IntNode head, int value)

            // Precondition:  Head is a reference to a linked list of integers,

// condition of the list is unknown (empty or not), int refers to value to be // added to the list at the END.

// Postcondition: List will have an additional node with the value placed in // it.

[Note] - break this into two parts - finding the right spot and then inserting.  The insert you already described up above - you just need to look for the last node; that node's link can be looked at as the "head" to your new node.  Don't forget to watch for empty case.

12)  The following is a code fragment used to count the # of occurrences of a specific "target" integer in an array.

         int i;

               int answer = 0;

               for (i = 0; i < data.length; i++)

               if (data[i] == target)

                  answer++;

Answer of course is the # of times the target is found in the array.  Rewrite the code so that it works correctly when the data array is an array of objects and target is a non-null reference to an object with an equals method.

13)  Suppose that the variable head is a reference to the head node of a linked list of objects. Each node has an instance variable called link (which is a reference to the next node) and another instance variable called data (which is an Object that's stored in the node). Write a few lines of code to count the number of occurrences of a specific non-null target Object on the list. At the end of your code, a variable called answer should indicate how many times the target appears in the array. Use target.equals to test for equality.

Reference no: EM13212152

Questions Cloud

What is the mass of the lead weight : What is the mass of the lead weight, if 100 J of heat is lost from the water after the weight falls a distance of 3 m.
What is the change of energy stored in the battery : A 12 Volt battery is charged by supplying 3 Amps over a period of 6 hours. What is the change of energy stored in the battery if the battery loses 400kJ of heat during charging.
Explain what is the heat of vaporization of the substance : A liquid substance has a vapor pressure of 450.0 mmHg at 262.0 degrees celsius and 760.0 mmHg at 325.0 celsius. a) what is the heat of vaporization of this substance? b) what is its normal boiling point?
Calculate marginal rate of technical substitution of labor : a. Graph the short run total product curves for each production function for 0  L  25 in the case where K is fixed at 4. b. Graph the marginal product of labor curves for each production function for 1  L  25. c. Do these production functions exh..
What are the values of these boolean expressions : Describe the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.
Compute ground state energy : calculate ground state energy, 1st excited energy level, and wavelenght of an electronic transition between the 2 lowest energy states for an electron
What does it mean for a production process to exhibit : What does it mean for a production process to exhibit "decreasing returns to scale" If a production process exhibits diminishing marginal returns to each of its inputs, will it necessarily also exhibit decreasing returns to scale
Explain the bubble point pressure and bubble composition : Assume that the system benzene and chlorobenze at 100 degree celcius obeys Raoult's law. for a binary mixture with an overall mole fraction Z=.30 determine
Community supported by various agencies and citizens : How are the arts in your community supported by various agencies and citizens? Do you think there is enough or not enough support of the arts by these entities? Explain why or why not

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a method called rectsum

Write a method called rectSum that will get the sum of a rectangle of elements within a 2D array of ints

  A java program where the user designates

a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2

  Java program to read line of text which ends with period

Write down the java program which will read the line of text which ends with the period, which serves as sentinel value. Show all the letters which occur in the text.

  All your code should be in the main method

Write a Java test program, all your code should be in the main method, that asks the user for two numbers representing an investment value and interest rate

  An infix to postfix method for my java program.

an infixToPostFix method for my java program. The method must work with stacks and it should take a string as parameter. The method should be able to convert to postfix mathematic expressions such as: (12 + 4) - 23(9-6)/12. Treat the parenthesis as l..

  Allows the user to enter a temperature and whether

Write a program that allows the user to enter a temperature and whether the temperature is stated in Celsius or Fahrenheit...or whethe

  Write a graphical user interface class

Write a graphical user interface class called SentenceCounterGUI. It should be able to manipulate the sentence of words and have the behaviour label.

  Ticketmaster

TICKETMASTER - this class will have: a service charge = $8.00 per ticket, tax = .085 current amount of all tickets sold. Its responsibilities are printing a list of events for sale, looking up an event for a customer, and selling a ticket to the e..

  Reimplement the labeledpoint class of exercise

Reimplement the LabeledPoint class of Exercise P9.12 by storing the location in a java.awt.Point object. Your toString method should invoke the toString method of the Point class.

  Create a gui version of the game mini sudoku.

Each row has the numbers 1 to 6,Each column has the numbers 1 to 6,Each group of 2 rows by 3 columns also has the numbers 1 to 6.

  Write a java program that reads unspecified number

Write a java program that reads unspecified number of integers (the input 0 signifies the end of the input). Calculates and displays the sum and the average of the input value (not counting zero). The program also finds the maximum and minimum of ..

  Which allows to input a year and when hit the check button

Create a JAVA GUI (With Frame), which allows to input a year and when hit the check button, will show the picture of Chinese zodiac animal! I am trying to make a calculator: i have the method for or the calculation method to show how to calculate:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd