Question

(20 pts) Inside a method main, we see code like:      Airplane.foo3(34.6); From this, reconstruct the...

  1. (20 pts) 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. (20 pts) 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. (40 pts) 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

public static void foo3(double num);

2.

public int foo4(String str);

3.

The error occurs because letterGrade is of type char, and the return type of toString() method is String.

To overcome this error, we can return

return letterGrade + "";

Add a comment
Know the answer?
Add Answer to:
(20 pts) Inside a method main, we see code like:      Airplane.foo3(34.6); From this, reconstruct the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (20 pts) Fill in the missing code: This recursive method returns “even” if the length of...

    (20 pts) Fill in the missing code: This recursive method returns “even” if the length of a give String is even, and “odd” if the length of the String is odd. public static String foo(String s) { if (s.length() ==0)    return “even”; else if (s.length() = = 1)    return “odd”; else     //your code goes here } (40 pts) You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n)...

  • 10. Recursive Append Download the file AppendRec.java. Write your code inside the appendNTimes method and use...

    10. Recursive Append Download the file AppendRec.java. Write your code inside the appendNTimes method and use the main method to test your code. Submit the file AppendRec.java. There is no need to delete the main method, the autograder will only grade appendNTimes. The method appendNTimes is recursive and takes two arguments, a string and an integer. It returns the original string appended to the original string n times. The method signature is as follows public static String appendNTimes ( String...

  • DESCRIPTION: The purpose of this question is offload processing from the main method to a static...

    DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" . METHOD INPUT: A string METHOD PROCESSING: Do not alter the  main method. Complete the...

  • in java Part 1 In this section, we relook at the main method by examining passing...

    in java Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Hello, so I need someone to look over this code and see if im on the...

    Hello, so I need someone to look over this code and see if im on the right path. I feel like im missing something. Here is the assignment: Create a class called Slogans. This class will extend the Thread class. This thread will read from a file several quotes that are on each line. It will pick a quote randomly and display it to the console. It will change quotes every 7 seconds. This will be updated in the final...

  • Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public...

    Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public class lastNameLE62 { private static Scanner in = new Scanner(System.in); private static int size; public static void arraySize() { System.out.printf("How many sports are you interested in? "); size = Integer.parseInt(in.nextLine()); } public static String[] setFavoriteSports() { String []favSports = new String[size]; for(int i=1; i<=size; i++) { System.out.printf("Enter sport #%d: ", i); favSports[i-1] = in.nextLine(); } return favSports; } public static String[] setFavoriteTeams(String[] sports) {...

  • Syntax checker. We will write C code to check to see if an input string can be derived from a gra...

    Syntax checker. We will write C code to check to see if an input string can be derived from a grammar. The grammar is: A ::= 0 B B ::= 1 A | 2 B | ; Your program "check.c" should output "yes" if the line of standard input can be derived from this grammar, and "no" otherwise. Here are some examples: $ ./check 0 ; yes $ ./check 0 2 1 ; no $ The input values will always...

  • This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and...

    This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and TweetManager. You will load a set of tweets from a local file into a List collection. You will perform some simple queries on this collection. The Tweet and the TweetManager classes must be in separate files and must not be in the Program.cs file. The Tweet Class The Tweet class consist of nine members that include two static ones (the members decorated with the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT