Question

In: Computer Science

For question 1 , consider that inside the class Sky, we have already coded the following:...

For question 1 , consider that inside the class Sky, we have already coded the following:

    public class Sky

     {

        private Color color;

        public Sky( Color c)

          {

              color = c;

          }

      }

  1.   Consider the following method header:

    public Color getColor();

Is this method a constructor, mutator or accessor?

  1.   Inside a method main, we see code like:

     Airplane.foo3(34.6);

From this, reconstruct the header of method foo3 (which belongs to class Airplane); make appropriate assumptions if necessary. Write the method header as your answer.

              

  1. Inside method main, we see code like:

Airplane a = new Airplane();

int n = a.foo4(“Hello”);

From this, reconstruct the header of method foo4 (which belongs to class Airplane)

Write the method header as your answer.

  1. You coded the following class:

You coded the following definition for the class Grade:

public class Grade

{

private char letterGrade;

public Grade(char 1g)

{

     letterGrade = lg;

   }

public String toString() //line 10

   {                                   //line 11

       return letterGrade;    //line 12

}                                    //line 13

}

When you compile, you get the following message:

Grade.java:12: incompatible types

return letterGrade;

           ^

found : char

required: String

1 error

Explain what the problem is and how to fix it.

Solutions

Expert Solution

1.

Solution:

  • The given statement public Color getColor(); is the accessor method.
  • The accessor methods are those that provides the accessibility to access a value.
  • Here, the given statement returns a Color object.

2.

Solution:

The reconstruction of the header is provided below:

public static void foo3(double value);

  • For the above statement, the assumption is that there is no return type and not getting any return value.
  • Since, the static functions are directly accessible by the class name.
  • Therefore, from the class Airplane the function foo1() is called.

3.

Solution:

The reconstruction of the header is as follows:

public int foo4(String s);

The function return an integer value and having the String as its parameter.

4.

Solution:

  • The generated error occurs because, the return type of the letterGrade is char and the function public String toString() tries to return a String.
  • The solution is to replace return letterGrade; to Character.toString(letterGrade);

Related Solutions

Question 1 price is an instance variable of a class. Inside that class there is a...
Question 1 price is an instance variable of a class. Inside that class there is a method public void change(int price). From inside the method " change" how do we refer to the instance variable price and not the parameter price? Answer: Question 2 A method of a class can access which of the following: 1 global variables in the same scope 2. local variables defined within the method 3. the instance variables of its class 4. its parameters Question...
2.) Postfix to infix translator (NOTE: This is NOT the evaluator you have already coded!) •...
2.) Postfix to infix translator (NOTE: This is NOT the evaluator you have already coded!) • Create a java class called PostfixToInfixTranslator that includes a main method. • The code you write should prompt the user for an expression in postfix notation and use ArrayStack to output the equivalent expression in infix. • See the following session: Enter a postfix expression: 3 4 + 2 * In infix notation that is: ((3+4)*2) Translate another expression [y/n]? y Enter a postfix...
There is already an existing class called Sizes, with an existing main method. Inside the Sizes...
There is already an existing class called Sizes, with an existing main method. Inside the Sizes class, create a method called menu. The purpose of this method is to display the menu on the screen and allow the user to make a choice from the menu. Do not change any of the existing code in the main method, and do not add code to the main method. Changing the main method in any way will give you an automatic grade...
This all counts as 1 question in class because it's supposed to be already known. So...
This all counts as 1 question in class because it's supposed to be already known. So please answer all of them. I just want to be sure I'm right. Question 1 Which of the following statements are true regarding momentum? Check all that apply. The total momentum of an isolated system is conserved, but internal forces can change the total momentum of the system pinitial = (m1v1)i + (m2v2)i + (m3v3)i + … pfinal = (m1v1)f + (m2v2)f + (m3v3)f...
The < and == operators for the class Record have already been implemented for you.
The < and == operators for the class Record have already been implemented for you. Write the code necessary to complete the >, <=,>= and != operators. (hint: you do not need to know anything about the Record class to complete)
In this project we will consider a particle sitting at the origin inside of a square...
In this project we will consider a particle sitting at the origin inside of a square whose sides intersect at the points (-10, -10), (-10, 10), (10, -10), and (10, 10). Each second, the particle moves in a random direction a random distance. That distance has an X as well as a Y component, each of which are standard normally distributed. 1.1 [8 points] Use R-Studio to model the following scenario: the particle moves every second as described above, use...
1. Why do historical archaeology if we already have historical/written records? Be familiar with an example...
1. Why do historical archaeology if we already have historical/written records? Be familiar with an example of how historical archaeology has either changed what we thought of the past or added information to the historical record. 2. Match the most appropriate trait to the dating technique. 1. Was used to date the Shroud of Turin a. Seriation            b. Opticaly stimulated luminescence            c. Carbon-14            d. Dendrochronology            e. Argon-Argon     ...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and...
Using C# Create the “TestQuestion” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” or “__str__” method, which will print the question followed by its answer. The constructor method has two parameters...
Consider the Mundell-Fleming model we have discussed in class for the small open economy. Suppose that...
Consider the Mundell-Fleming model we have discussed in class for the small open economy. Suppose that higher income implies higher imports and thus lower net exports. That is, the net-exports function is NX = NX(e, Y ) Examine the effects in a small open economy of a fiscal expansion on income and the trade balance under the following exchange-rate regimes: 1. A floating exchange rate (5 points) 2. A fixed exchange rate (5 points)
Consider the following processes we've discussed in class. In which of these processes can we observe...
Consider the following processes we've discussed in class. In which of these processes can we observe evolutionary conflict? Group of answer choices A) multi-level selection B) sexual selection C) Coevolution D) Genetic drift A, B, and C A and B All of the above A, B, and D
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT