Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 2

State whether each of the following is true or false. If \(f a l\) se, explain why. a) By convention, method names begin with an uppercase first letter and all subsequent words in the name begin with a capital first letter. b) An import declaration is not required when one class in a package uses another in the same package. c) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task. d) Variables or methods declared with access modifier private are accessible only to methods of the class in which they are declared. e) A primitive-type variable can be used to invoke a method. f) Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class. g) Every method's body is delimited by left and right braces ( \(\\{\text { and }\\}\) ). h) Primitive-type local variables are initialized by default. i) Reference-type instance variables are initialized by default to the value null. j) Any class that contains public static void main( String args [] ) can be used to execute an application. k) The number of arguments in the method call must match the number of parameters in the method declaration's parameter list. I) Floating-point values that appear in source code are known as floating- point literals and are type float by default.

Problem 3

What is the difference between a local variable and a field?

Problem 4

Explain the purpose of a method parameter. What is the difference between a parameter pro and an argument?

Problem 5

What is the purpose of keyword new? Explain what happens when this keyword is used in an application.

Problem 6

What is a default constructor? How are an object's instance variables initialized if a class has only a default constructor?

Problem 7

Explain the purpose of an instance variable.

Problem 8

Most classes need to be imported before they can be used in an application. Why is every application allowed to use classes System and String without first importing them?

Problem 10

\(3.10 \quad\) Explain why a class might provide a set method and a get method for an instance variable.

Problem 11

Modify class GradeBook (Fig. 3.10 ) as follows: a) Include a second String instance variable that represents the name of the course's instructor. b) Provide a set method to change the instructor's name and a get method to retrieve it. c) Modify the constructor to specify two parameters - one for the course name and one for the instructor's name. d) Modify method displayMessage such that it first outputs the welcome message and course name, then outputs "This course is presented by:" followed by the instructor's name. Use your modified class in a test application that demonstrates the class's new capabilities.

Problem 14

Create a class called Employee that includes three pieces of information as instance variables - a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, set it to \(0.0 .\) Write a test application named EmployeeTest that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a \(10 \%\) raise and display each Employee's yearly salary again.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks