homework

CIS 36A :: LAB 04 - Introducing Classes, Objects and Methods
Student Name:
Instructions:

Make a copy of assignment template. Go to File => Make a copy (or download as a Word file.)
Complete definitions and attach Snipping Photos where appropriate
Place your name in the Title of each Assignment

For Example: CIS 36A- Assignment 1 - Basic Concepts -  Irfan O.


Use the book or do online research to find answers. 
Write your answers using a different font color. Find your own unique color. 
Write answers in your own words. DO NOT COPY & PASTE from anywhere.
Submission: When done, go to File -> Download as -> Microsoft Word and then upload the file to Canvas. 

Task 1: Definitions & Concepts
Instructions: Briefly answer the questions below.

Keywords: To you best knowledge, describe below words: 
    
class =>  
method => 
return  =>
void => 
this =>  
object => 
constructor => 
new => 


What is the difference between a class and an object?
=> 
How is a class defined?
=> 
How must a method return if it returns a value?
=> 
What name does a constructor have? 
=> 
If a method returns no value, what must its return type be? 
=> 

Task 2: Understanding Programming
Instructions: Answer each question below. Try to understand and explain the code. Do not put an IDE code screenshot. 

Exercise 15: Suppose you have a class MyClass with one instance variable x. What will be printed by the following code segment?
 MyClass c1 = new MyClass();
 c1.x = 3;
 MyClass c2 = c1;
 c2.x = 4;
 System.out.println(c1.x);
Explain your answer.
=> 
Exercise 16: Suppose a class has an instance variable x and a method with a local variable x.
    
If x is used in a calculation in the body of the method, which x is being referred to?
=> 
Suppose you needed to add the local variable x to the instance variable x in the body of the method. How would you do so?
=> 


Exercise 17: The following method has a flaw (in fact, due to this flaw it will not compile). What is the flaw?

void displayAbsX(int x) {
     if (x > 0) {
         System.out.println(x);
     return;
     }
    else {
         System.out.println(-x);
         return;
    }
    System.out.println(“Done”);
  }
=> 

Exercise 18: Create a method max( ) that has two integer parameters x and y and returns the larger of x and y.
=> 
Exercise 19: Create a method max( ) that has three integer parameters x, y, and z, and it returns the largest of the three. Do it two ways: once using an if-else-if ladder and once using nested if Statements.
=> 
Exercise 21: Find all the errors (if any) in the following class declaration:
 Class MyCla$$ {
     integer x = 3.0;
     boolean b == false

     // constructor 
     MyClass(boolean b) { b = b; }
     int doIt() {}
     int don’tDoIt () { return this; }
 }
=> 

Task 3: Programming Exercises
Instructions: Use any IDE to write and execute below exercises from the book chapter 3. Attach Snipping photos of your source code and execution of the code in the console. Make sure to create separate files for each exercise. 

Chapter Examples: Follow the lectures to do below programs with the instructor.  

Day 1: MethodDemo 
Day 2: The last version of your VehicleDemo class
Create a BankAccount class with one integer instance variable called balance. Create a constructor with no initial parameters.  Create three methods: one for deposit, one for withdrawal, one for get balance. 

TRY THIS

TRY THIS 4-1 (Do not submit this):
TRY THIS 4-2:

Chapter Exercises: Do the following chapter exercises.

Exercise 13: Die, DieDemo
Exercise 14: Car, CarTester
Exercise 22: Swapper
Exercise 24: USMoney
Exercise 25: Date
Exercise 26: DoIt
  1. Question Attachments

    1 attachments —

Answer Detail

Get This Answer

Invite Tutor