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

Need help in java. 1. You are asked to write a method that accomplishes each of

ID: 3668481 • Letter: N

Question

Need help in java.

1. You are asked to write a method that accomplishes each of the following tasks. What would be the return type of the method?

a. echo a "hello world" message to the user

b. determine if a number is even

c. generate a username for a website

d. calculate the sum of five integers

Which of the following could be a return type for a method? Select all that apply.

Select one or more:

a. void

b. int

c. AudioItem

d. String

e. boolean

3. What is the header for the toString method?

4. Every class in Java has a no-argument constructor.

Select one:

True

False

5. A method defined in a class can access the class’ instance data without needing to pass them as parameters or declare them as local variables.

Select one:

True

False

Answer:

4.

Which of the following is true? Select all that apply.

Select one or more:

a. Constructors always have the same name as the class.

b. Constructors are used to initialize instance variables.

c. A class can only have one constructor.

d. The compiler always creates a default constructor (a constructor with no arguments) for a class.

e. Constructors can invoke other methods in the class.

6. Write a class header for a class that would represent a car.

Answer:

7.

Which of the following are visibility modifiers? Select all that apply.

Select one or more:

a. static

b. private

c. protected

d. final

e. public

a. echo a "hello world" message to the user

Answer 1Choose...void, Scanner, int, double, String, boolean

b. determine if a number is even

Answer 2Choose...void, Scanner, int, double, String, boolean

c. generate a username for a website

Answer 3Choose...void, Scanner, int, double, String, boolean

d. calculate the sum of five integers

Answer 4Choose...void, Scanner, int, double, String, boolean

Explanation / Answer

1.

The return types of the different methods are as follows:

a. echo a “hello world” message to the user.

     The return type will be void because it will return the message and does not require any return   

type other than void.

b. determine if a number is even

The return type will be Boolean because the possibility that either the number is even or not.

c.generate a username for a website

The return type will be String because the user name is required to be generated so the output should be a collection of numbers, letters, special characters. So, the return type should be a string.

d.calculate the sum of five integers

The return type should be int because the sum of five integers which will be calculated will be an integer. So, the value returned will be sum which is an integer.

2.

The return type for a method will be void. This is because any method that is declared void does not return a value. It does not require a return statement if declared void. The return type for a method can also be class name or primitive data type.

Hence, from the options mentioned the correct option will be a) Void

3.

The return type of the toString () method is as follows:

public String toString ()

This method is used to convert an object to a String.

4   

It is true that every class in Java has a no-argument constructor that is the default constructor.

The default constructor calls the parent’s no-argument constructor or the object’s constructor

5.

The statement “A method defined in a class can access the class instance data without needing to pass them as parameters or declare them as local variables” is true.

This is because the instance data is available to all methods of the class and the methods require the instance data to be received as parameters or declared locally.

4

The statements which are true are as follows:

a. Constructors always have the same name as the class.

b. Constructors are used to initialize instance variables.

d The compiler always creates a default constructor for a class.

e. Constructors can invoke other methods in the class.

6.

The class header for a class that would represent a car is as follows:

   public class Car

      {

           int model;

           int speed;

         public ()

           {

                  model = 1330;

                  speed = 0;

            }

         

       }

7.

The visibility modifiers are:

b. private

c. protected.

e. public.

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