[Solved] CS20B Homework 1

$25

File Name: CS20B_Homework_1.zip
File Size: 150.72 KB

SKU: [Solved] CS20B Homework 1 Category: Tag:
5/5 - (1 vote)
  1. What is the difference between an object and a class? Give two examples.
  2. Explain the difference between
    • int a = 3;

and

  • Integer a = new Integer(3);
  1. For the following concepts/classes define/write at least one method:
    • Animal
  • Dog
  • User
  • File
  • Database
  1. Q. For the following concepts/classes write at least one instance variable/attribute and an associated constructor you can define taking more than one input argument/parameter:

(a) MobilePhone

(b) User A.

(c) File

(d)Database

(e) Webpage

  1. What is the output of the following program:

class T { private int t = 20;

T(){

t = 40;

}

} class Main {

public static void main (String args []) {

T t1 = new T();

System.out.println(t1.t);

}

}

6. Is there any compiler error in the below Java program? Please explain your answer.

I dont accept only yes or no.

class Point {

int m_x, m_y; public Point (int x, int y) {m_x = x; m_y = y;} public static void main (String args []) { Point p = new Point();

}

}

7. Some aspects of each of the following can be modeled with a graph (network) structure. Describe, in each case what the nodes would represent and what the edges would represent. In general, nodes represent concepts/entities, and edges explain what the relationship is between the entities. For example, for navigation, nodes would represent locations (cities, towns, ) and edges between cities represent if a road exists between them (a weight can be added to denote the distance).

    • Airline
  • Social networks such as Facebook
  • The Internet
  • Movie industry
  • Avengers (the movie/comic)
  • Amazon.com recommendation system (where a system recommends to you what to buy)
  1. Describe and specify the order of growth of each of the following code sections, using big-O notation (explain your answer!):

(a) int count = 0; for (int i = 1; i < = N; i++) count ++;

(b) int count = 0; for (int i = 1; i <= N; i++)

for ( int j = 1; j <= N; j++) count ++;

(c) int count = 0; for (int i = 1; i <= N; i++) count ++;

for (int j = 1; j <= N; j++) count ++;

(d) int count = 0; for (int i = 1; i <= N/2; i++)

for ( int i = 1; i <= N/2; i++) count ++;

(e) public static String reverse ( String s) { int n = s.length(); char [] a = new char[n]; for (int i = 0; i < n; i++) a[i] = s.charAt(n-i-1); String reverse = new String (a); return reverse;

}

9. Describe the order of growth of each of the following functions using O notation:

(a) N2 + 3 N.

(b) 3 N + N

(c) N (N 1) + 2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS20B Homework 1[Solved] CS20B Homework 1
$25