Capability4 Assignment
Capability4 Assignment
Capability4 Assignment
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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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.
2
Basecamp Capability 4 Assignments
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.
SavingsAccount
-balance: double
-interestRate:int
-accountNo:int
+SavingsAccount()
+SavingsAccount(double, int, int)
+void withDraw(double amount)
+void calculateInterest()
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
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
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
8
Basecamp Capability 4 Assignments
class Emp
{
private int empNumber;
private String name;
void disp()
{
System.out.println("empNumber ="+empNumber);
System.out.println("name ="+name);
}
Emp getEmp()
{
Emp emp=new Emp(30,"Tom");
return emp;
}
9
Basecamp Capability 4 Assignments
class Student
{
private int rollNumber;
private String name;
10
Basecamp Capability 4 Assignments
class StudentConstructor
{
private int rollNumber;
private String name;
11
Basecamp Capability 4 Assignments
void disp()
{
System.out.println("rollNumber ="+rollNumber);
System.out.println("name ="+name);
}
class StudentNew
{
private int rollNumber;
private String name;
StudentNew()
{
System.out.println("Default Constructor");
rollNumber=0;
name="";
12
Basecamp Capability 4 Assignments
void disp()
{
System.out.println("rollNumber ="+rollNumber);
System.out.println("name ="+name);
}
13
Basecamp Capability 4 Assignments
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