Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Capability4 Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Basecamp Capability 4 Assignments

Introduction:
This document covers list of assignments/exercises related to fourth capability of
Basecamp program:
Design and implement applications using basic OOP paradigms.

Observations:
KO: 1. Proper entity classes identified and implemented?
KO: 2. Ability to initialize data members using constructors and setter methods
KO: 3. Ability to implement array of objects as per problem statement
4. Ability to pass array of objects as argument to a method and return an array from a
method

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Exercise 1: Employee Class and Object


Write a program as below guideline:

1. Create an Employee class with following attributes:

Employee
-empId: int
-empName:String
-empDesig:String
-empDept:String
+Employee()
+getters()
+setters()
+Employee(int, String, String, String)

1
Basecamp Capability 4 Assignments

2. Write a program, which creates an instance of employee class and sets the
values for all the attributes.

 While setting value for empName, setEmpName() method should check for
NullPointer and display appropriate error message.

 While setting value for empDesig, the designation must have any of the
following values: developer, tester, Lead or manager. If none of these values
is matching then setter method should display 'Invalid designation' error
message.

 While setting value for empDept, the department must have any of the
following values: TTH, RCM, Digital, DevOps. If none of these values is
matching then setter method should display 'Invalid Dept' error message.

Exercise 2: Book Store


Develop a program that assists book store employees. For each book, the program
should track the book’s title, its price, its year of publication, and the author’s name. . . .
Develop an appropriate Java Class. Create instances of the class to represent these
three books:
 Daniel Defoe, Robinson Crusoe, $15.50, 1719;
 Joseph Conrad, Heart of Darkness, $12.80, 1902;
 Pat Conroy, Beach Music, $9.50, 1996.

2
Basecamp Capability 4 Assignments

Exercise 3: XYZ Bank


XYZ bank wants to maintain customer details. It will register the customer details
whenever a person opens an account with the bank. Below is the customer class
diagram:

Customer

-custId:int
-custName:String
-custAddress:String
-accType:String
-custBalance:double
+getters and setters methods()

At times, the customer registration process changes, here are the guidelines:
1. Admin may register customer by filling only ID, name and address details
2. Admin may register customer by filling only ID and name
3. Admin may register customer by filling all the details.

Write an application which implements above scenario. Write main method in separate
class, which creates different customer objects and invokes appropriate constructors,
here is sample code:

3
Basecamp Capability 4 Assignments

Note: When other data members which are not initialized through constructors should
have appropriate default values.

Exercise 4: Savings Account


Implement below given class diagram. Invoke constructor and methods of this class by
creating appropriate object in main method.

SavingsAccount

-balance: double
-interestRate:int
-accountNo:int
+SavingsAccount()
+SavingsAccount(double, int, int)
+void withDraw(double amount)
+void calculateInterest()

Implement the withDraw(double amount) method: If amount is greater than balance


then display error message; otherwise debit amount from balance and display the
message “successfully withdrawn” + amount
Implement the calcuateInterest() method: calculation of simple interest for the balance
maintained in the saving account.

Exercise 5: Coffee Shop

A coffee shop would like to find out the customer feedback rating about its services.
The customer class shown below:

4
Basecamp Capability 4 Assignments

Customer

-Name:String
-MobileNo:String
-feedbackRating:dobule
+Customer()
+Customer(String, String, double)
+getters()
+setters()

Example: Assume that the shop will collect feedback from ‘N’ customers. Following are
the sample customer feedback values.
Customer 1: 3 out of 5
Customer 2: 4 out of 5
Customer 3: 2.5 out of 5

Write an application which creates array of ‘N’ customer objects and display average
feedback rating. Further display customer details who has given low and high feedback.

5
Basecamp Capability 4 Assignments

Exercise 7: Class Diagram and relationships


Analyze following class diagram and answer below questions.

Employee
Company
-name:String
-name:String -employeeNumber:int
-employees[]:Employee -salary:int
-manager:Manager
+String getName() 1..*
+Employee[] getEmployees() +String getName()
+employer works for +employee +int getEmployeeNumber()
+int getSalary()
+Manager getManager()

1..*
+supervises
Manager
-manages[]:Employee
Contractor
+void addTeamMembers()
+Employee[] getTeamMembers() -lengthOfContract:Date

+Date getLengthOfContract()
+supervisor

a) Identify classes
b) Identify the relationships between each classes
c) Identify the attributes and methods

Exercise 8: Student Database

Objective:
Given a class diagram for a problem, use the method and constructor overloading
concepts to solve the problem and test using a set of values in an IDE.
Problem Description: The admin of a pre-university college wants to calculate the marks
of students in a particular course based on some criteria. Write a Java program to
implement the below given class diagram.

6
Basecamp Capability 4 Assignments

Student
-studentId: int
-studentName: String
-marks: float
-secondChance: boolean
+Student(int,String,String)
+getStudentId(): int
+getStudentName(): String
+getMarks(): float
+getSecondChance():
Boolean
+identifyMarks(float): void
+identifyMarks(float, float):
void

Student Class:
Constructor: Initializes studentId, studentName and secondChance.
identifyMarks(float) method:
This method is used to set the marks of the student if the student has cleared in the first
chance itself, i.e. second chance is false. This method accepts the marks scored by the
student which must be set in the marks instance variable.
identifyMarks (float, float) method:
This method is used to set the marks of the student if the student has taken the second
chance i.e. second chance is true. This method accepts the marks scored by the
student in the first chance and second chance. The maximum of both these marks must
be identified and set in the marks instance variable.
Starter Class:
Write a starter class named Demo,
Step1: Create an object of Student class by passing appropriate values to the
constructor.
Step2: Based on the value used for second chance instance variable, invoke the
appropriate identifyMarks() method.
Step3: Invoke the getter methods and display all the instance variable values of the
Student object created. Create one more object (use different value for second chance)
by repeating steps 1 to 3 and test your program.

7
Basecamp Capability 4 Assignments

Exercise 9: Employ Record Sorting and Searching

Create menu driven program to implement following scenario:


1. Add Employee Details
2. Display Employee Names in sorted order based on branch (alphabetical order)
3. Display Employee ID in ascending order
4. Display Employee details who has salary > 50000
Note: Each Employee must have ID, name, Department and salary. Use methods for
each option to implement.

Exercise 10: Test your skill

Attempt questions given in the following URL:


https://docs.oracle.com/javase/tutorial/java/javaOO/QandE/objects-questions.html

Exercise 11: Find the output


Execute the program and understand the problems, if you find any error then correct it!

8
Basecamp Capability 4 Assignments

Exercise 12: Find the output


Execute the program and understand the problems, if you find any error then correct it!

class Emp
{
private int empNumber;
private String name;

Emp(int empNumber,String name)


{
this.empNumber=empNumber;
this.name=name;
}

void disp()
{
System.out.println("empNumber ="+empNumber);
System.out.println("name ="+name);
}
Emp getEmp()
{
Emp emp=new Emp(30,"Tom");
return emp;
}

public static void main(String arg[])


{
Emp emp1=new Emp(10,"Mary");

9
Basecamp Capability 4 Assignments

Emp emp2=new Emp(20,"Jerry");


Emp emp3=emp1.getEmp();
emp2=emp1;
emp1.disp();
emp2.disp();
emp3.disp();
}
}

Exercise 13: Find the output


Execute the program and understand the problems, if you find any error then correct it!

class Student
{
private int rollNumber;
private String name;

void setStudent(int rno,String sname)


{
rollNumber=rno;
name=sname;
}

private void disp()


{
System.out.println("rollNumber ="+rollNumber);
System.out.println("name ="+name);
}

10
Basecamp Capability 4 Assignments

public static void main(String arg[])


{
Student s1=new Student();
Student s2=new Student();
s1.disp();
s1.setStudent(101,"Jack");
s2.setStudent(102,"Tom");
s1.disp();
s2.disp();
}

Exercise 14: Find the output


Execute the program and understand the problems, if you find any error then correct it!

class StudentConstructor
{
private int rollNumber;
private String name;

StudentConstructor(int rollNumber,String name)


{
this.rollNumber=rollNumber;
this.name=name;
}

11
Basecamp Capability 4 Assignments

void disp()
{
System.out.println("rollNumber ="+rollNumber);
System.out.println("name ="+name);
}

public static void main(String arg[])


{
StudentConstructor s1=new StudentConstructor(101,"Jack");
StudentConstructor s2=new StudentConstructor();
s1.disp();
s2.disp();
}
}

Exercise 15: Find the output


Execute the program and understand the problems, if you find any error then correct it!

class StudentNew
{
private int rollNumber;
private String name;

StudentNew()
{
System.out.println("Default Constructor");
rollNumber=0;
name="";

12
Basecamp Capability 4 Assignments

StudentNew(int rollNumber,String name)


{
System.out.println("OverLoaded Constructor");
rollNumber=rollNumber;
name=name;
}

void disp()
{
System.out.println("rollNumber ="+rollNumber);
System.out.println("name ="+name);
}

public static void main(String arg[])


{
StudentNew s2=new StudentNew();
StudentNew s1=new StudentNew(101,"Jack");
s1.disp();
s2.disp();
}
}

13
Basecamp Capability 4 Assignments

Exercise 16: Find the output


Execute the program and understand the problems, if you find any error then correct it!

class Access
{
private int a;
public int d;
}

class AccessSpec
{
public static void main(String arg[])
{
Access access=new Access();
System.out.println(access.a);
System.out.println(access.d);

}
}

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Summary:
You must have learnt following concepts:
 How to create a class and objects
 How to identify classes and its members
 How to use constructors
 How to create array of objects
 How to pass an object to a method and how to return?

14

You might also like