Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

Day 1

1. Refer to "Installation Instructions" from day1-data\day1_help & complete.

2. MUST go through "readme_day1" from day1-data\day1_help\readmes & day1-data\


day1_help\slides\PPTDay1.pdf

3. Go through simple code samples from day1-data\code\src

4. Solve

4.1. Accept 2 double values from User (using Scanner). Check data type.
. If arguments are not integers , supply suitable error message & terminate.
If numbers are integers , print its average.

4.2. Create java application(program) to display food menu to user.


User will select items from menu along with the quantity. (eg 1. Dosa 2. Samosa
3.Idli 4. Rice 5 . Generate Bill ) Assign fixed prices to food items(hard code the
prices)
The program should continue to run , till user selects 'Generate Bill' i.e 5th
option.
When user enters 'Generate Bill' option(5) , display total bill & exit.

5. Reading H.W
5.1 Go through "readmes" folder.

5.2 Optional work

For introduction to JVM Architecture , refer :


https://www.freecodecamp.org/news/jvm-tutorial-java-virtual-machine-architecture-
explained-for-beginners/

We have NOT yet covered entire architecture.

Day 2
1. Refer to readme & revise the class work
2.
Solve Tank assignment along with memory picture.

What will be the output ?

class Tank {
private int level;
Tank(int level)
{
this.level=level;
}
public void setLevel(int level1)
{
level=level1;
}
public int getLevel()
{
return level;
}
}

public class Assignment {


public static void main(String[] args) {
Tank t1 = new Tank(10);
Tank t2 = new Tank(20);
s.o.p("1: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());//10 20
t1 = t2;
s.o.p("2: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());//20 20
t1.setLevel(27);
s.o.p("3: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());//27 27
t2.setLevel(t1.getLevel()+10);
s.o.p("4: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());//37 37
}
}

3. Solve this (Will be discussed in detail in the lab session)

Modify box class , to supply following functionality & test it using a separate
class TestBoxFunctionality.java

3.1 Create Cube


TestBoxFunctionality.java
sop("Enter side of a cube");
Box abc=new Box(sc.nextDouble());
sop("vol of cube "+abc.getBoxVolume());
Box.java : add another constr : 1 single arg.

3.2. Add a method to Box class to compare equality of 2 boxes & test it.
Hint : 2 boxes are equal if & only if , their dimensions are exactly the same.
eg : Tester code
sc
sop("Enter 1st Box dims");
Box b1=new Box(....);//10 20 30
sop("Enter 2nd Box dims");//20 10 30
Box b2=new Box(....);

//invoke the method


boolean status=b1.checkEquality(b2);
if(status)
sop("SAME");
else
sop("DIFFERENT");

//add a method in Box class to test the equality


boolean checkEquality(Box anotherBox)
{
return this.width==anotherBox.width && .......;
}

3.3 Add a method to Box class to return a new Box with modified offset dims & test
it with the tester.
eg :
//user has already asked for 1 box
Box b1=new Box(......);//1st box created.: 10 20 30
sop("Enter the offsets from the 1st box dims : width-offset depth-offset height-
offset ");//5 -3 -4
Box newBox=b1.createNewBox(.....);//offsets
//another new box : 15 17 26
3.4 Display color of the box , having larger volume.
eg : Box b1=new Box(...);//10 20 30,red
Box b2=new Box(...);//20 30 40,green
b1.getBoxVolume() ... b2.getBoxVolume() --- display color

4. Solve ready code samples from : day2_data\day2_help\params_passing\


TestParamPassing1 & TestParamPassing2

5. Test packaged code sample.


How ?
From cmd prompt --from day2\src
javac -d ..\bin tester\TestPackage.java
cd..\bin
java tester.TestPackage

Day 3
1. Revise classwork

2. Instead of setting the CLASSPATH , using environment variables , you can use
this command on all platforms
eg : java -cp "D:\IACSD-Sep21\pg-dac\day3.1\bin"
com.app.tester.TestBoxFunctionality
(Please edit it as per your folder path)

3. Solve ready code samples from : day2_data\day2_help\params_passing\


TestParamPassing1 & TestParamPassing2

4. Coding assignment

4.1 Create a class Point2D , in package - "com.app.geometry" : for representing a


point in x-y co-ordinate system.

4.2 Create a parameterized constructor to init x & y co-ords.

4.3 Add a method to return string form of point's x & y co-ords


Hint : public String getDetails())

4.4 Add isEqual method to Point2D class :a boolean returning method : must return
true if both points are having same x,y co-ords or false otherwise.
eg : public boolean isEqual(Point2D anotherPoint)
{
.......
}
eg : p1.isEqual(p2)

4.5 Add calculateDistance method to calculate distance between current point and
specified point & return the distance to the caller.
Hint : Use distance formula . Use java.lang.Math class methods --sqrt, pow etc.
eg : public double calculateDistance(Point2D anotherPoint)
{
Math.sqrt(.....);
}

4.6 Write TestPoint class , in package "tester" , with a main method


Accept co ordinates of 2 points from user (Scanner) --to create 2 points (p1 & p2)
4.7 Use getDetails method to display point details.(p1's details & p2's details)

4.8 Invoke isEqual & display if points are same or different (i.e p1 & p2 are
located at the same position)

4.9 Display distance between p1 & p2

Day 4
1. Revise class work & complete pending assignments.

2.Solve ready code samples from : day2_data\day2_help\params_passing\


TestParamPassing3 & TestParamPassing4

3. I will discuss additional assignments , after I join the lab session.


3.1 Create a new eclipse project day4_assignments
3.2 Copy the package "com.app.geometry" below src
3.3 Create a class "TestPointArray1.java" in "tester" package for the following
3.4 Accept , how many no of points to plot from user.
3.5 Create suitable data structure(array) (How ??? : Point2D[] points=new
Point2D[sc.nextInt()];
3.6 Prompt user for x & y co ordinates n store the data suitably (How )
for loop
for(int i=0;i<points.length;i++)
{.....}

3.7 Supply Menu to user


Options
1. Dsiplay details of a specific point
User i/p : index
O/p : x & y co-ordinates or error message(eg : Invalid index , pls retry!!!!)

2. Display x, y co-ordinates of all points


eg : for / for-each

3. User i/p : 2 indices for the points , validate the indices


Display distance between specified points

eg : suppose 10 points are plotted(10 instances of Point2d class are created in


heap n their refs are kept in the array)
valid range of indices are : 0---9
sop ("Enter strt index n end index, to calculate the distance");
int start=sc.nextInt();
int end=sc.nextInt();
//validate them
After validation , invoke "calculateDistance" method

4. Exit

4. Simple assignment to understand inheritance (Optional)

Can you arrange Fruit,Apple,Orange,Mango in inhertinace hierarchy ?


Use tight encapsulation.

Fruit : color : String , weight : double


Apple,Orange,Mango : color : String , weight : double
Add a taste() method : public String taste()

For Fruit : it should return "no specific taste"

Apple : should return "sweet n sour"


Mango : should return "sweet"
Orange : should return "sour"

Add all of above classes under the package "com.app.fruits"


Add TestFruits under package "tester"
Using scanner accept details of individual fruit(color & weight)
Display it's details (by overrding toString)
Display it's taste. (HOW : by calling taste)

Day 5
1. Complete pending assignments
2. Revise class work

3. Create a new eclipse project "day5_assignemnts"


3.1 Copy the package "com.app.fruits"
Add a data member in Fruit class : private String name.
Name should get initialized to "Apple" or "Orange" or "Mango" correctly , using sub
class constructor
Add specific methods
In Mango : public void pulp() {...}
In Orange : public void juice() {...}
In Apple : public void jam() {...}

3.2 Create java application FruitBasket , with main


3.3 Prompt user for the basket size n create suitable data structure
3.4 Supply options
1. Add Mango
2. Add Orange
3. Add Apple
4. Display name of the fruit along with tastes of all the fruits in the basket ,
along with invocation of their pulp or juice or jam method invocation.
eg : For Mango :
Mango tastes Sweet . Can be pulped !
For Orange
Orange tastes Sour . Can extract juice!
10. Exit

Day6
1. Complete pending work.

2. Revise day6.1 for abstract classes & day6.2 for interfaces


(refer to readmes n interface help)

3. Refer to fruits scenario , of yesterday's assignment


Can you think of any better(cleaner) solution ?
Hint : abstraction

4. Will discuss fresh assignments later.


Apply inheritance , polymorphism & abstraction to emp based organization scenario.

Create Emp based organization structure --- Emp , Mgr , Worker


All of above classes must be in package--com.app.org

4.1 Emp state--- id(int), name, deptId(string) , basic(double)


Accept name, dept id , basic salary in constructor arguments.
Generate emp id (HOW ?????)
Behaviour ---1. get emp details -- toString

4.2 Mgr state ---id,name,basic,deptId , performanceBonus

Behaviour ----1. get mgr details :


eg : @Override
public String toString()
{
return "Mgr "+super.toString()+" bonus "+performanceBonus;
}
2. compute net salary (formula: basic+perfmonceBonus)
3. get performance bonus.

4.3 Worker state --id,name,basic,deptId,hoursWorked,hourlyRate


Behaviour---
1. get worker details --
2. compute net salary (formula: = basic+(hoursWorked*hourlyRate)
3. get hrlyRate of the worker -- add a new method to return hourly rate of a
worker.(getter)

Can you organize these classes in inheritance hierarchy?

4.4 Write TestOrganization in "tester" package.


Create suitable array to store organization details.

Provide following options. Run the application till "exit"

1. Hire Manager

2. Hire Worker

3. Display information of all employees , including net salary using single for-
each loop.
Display from the same for-each loop, performance bonus if it's a manager or if it's
a worker , display hourly rate of the worker .

4. Update basic salary


i/p : emp id & basic salary increment
o/p : In case of invalid emp id , give suitable error message. Otherwise ,
increment the salary.

5. Exit

Day 7

1. Try to complete Day 6 emp orgnization assignment.

2. Import day7.1 --for understanding interfaces


import day7.2 --- for understanding reference equality in Object class's equals
method
import day7.2 --for understanding overrding of equals method
import day7.3 for access specifiers (mainly protected)

3. I will also revise important code samples , after I join the lab session
& then discuss fresh assignments.
New assignment
Requirement : Create Java application for Student registration
Student's attributes - rollNo (int) , subject (String), firstName , lastName ,
gpa(grade point average)
Consider 2 students are same if & only if their rollNo & subject is same.
Supply suitable constructor , toString & ?????
Hint : For comparing 2 subjects : Use String class's equals method

Create a tester for Student management.


Options
1. Admit Student
Check boundary conditions , in case of success insert new student details
Validation Rule : App should not accept dup student details (HOW : Student's
equals)
Give a message accordingly (Admitted successfully or failure)

2. Display details of all admitted students.

3. Exit

Day 8
1. Complete pending assignment.
(Take help from day8.1 eclipse project for overrding equals)

2. import day8.2 project. Revise checked vs un checked excpetion ,


try,catch,finally, try-with-resources,throw , throws & custom exception --using
readmes (shared yesterday) & code

3. Will discuss new assignment later.

Day 9
1. import day9.1 n revise string handling & date time handling in java

2. We will start solving the emp based objective , after your revision, as
discussed in theory session.

Day 10
1. Try to complete emp based assignment , if any part is yet pending
(refer to eclipse project : day9_lab)
2. Refer to readmes n day10.1 & revise enum

3. We will discuss further work after I join the lab session.


Add another option
Update Emp's salary & dept.
User i/p : emp id , new dept id ,salary increment
O/p : In case of invalid emp id --display err mesg (via custom exc)

In case of valid emp id , validate new dept id --in case of success --change dept n
apply salary increment .

Day11
1. import eclipse project : day11_lab , in your workspace , to understand
aggregation between Emp & AdharCard
1.1 refer to TestAssociation.java
1.2 refer to TestEmpOrganization

2. import day11.1 , to revise wrapper classes n nested classes in java


3. import eclipse project : day11_lab2 , in your workspace , to understand
composition between Emp & AdharCard
3.1 refer to TestAssociation.java
3.2 refer to TestEmpOrganization (It's same as earlier)

4. Refer to ready code . Copy Vehicle class in new eclipse projects : day11_lab3
Form Composition between Vehicle & DeliveryAddress
DeliveryAddress : city ,state,country, zipCode

Test it with a simple tester. (No while or switch-case expected)


Steps
4.1 Prompt user for Vehicle details & create vehicle instance
4.2 Prompt user for delivery address details & form a link
4.3 Display complete vehicle details ,containing delivery address.

Question : If Unique ID (=equality criteria) for Emps : empId , deptId, joinDate


How will you support it ?
Ans : 1. Modify equals method of Employee class , to check equality of empId ,
deptId, joinDate
2. Add overloaded constructor to init : empId , deptId, joinDate
3. Modify validation rule --validateEmpId & getEmpDetails
4. From Tester : accept details for empId , deptId, joinDate , in option 3.

Day12
1. import day11_lab3 , to refer to earlier assignment solution
(Purchase a Vehicle)

2. import day12.1 : revise non generic vs generic


Refer to Collection Framework PPTs , readmes n diagrams . Revise the code samples.

Day 15
1. import day15.1 n revise hashing algorithm using code samples n diagram n
observations.txt

2. import day15.2 n revise LinkedHashSet n TreeSet

3. From day15.2 , TestTreeSet1.java


Solve pending assignment : arrange the integers in desc order using custom ordering
of TreeSet + anonymous inner class

4. Fresh assignment

4.1Arrange Student details in a suitable data structure , to ensure constant time


performance for add/remove/search operations
Student's attributes - rollNo (int) , subject (String), firstName , lastName ,
gpa(grade point average)
PK : rollNo & subject
4.2 Accept at least 5 student details from user(using scanner) & confirm if data
structure is working in a correct manner.
(Hint : use HashSet)

4.3 Display student details sorted as per gpa , using custom ordering in Set
(Hint : use TreeSet)

Day16

1. Complete pending assignment , if any.

2. import day16.1 to revise , Java 8 Date / Time API


3. import day16.2 to revise Map functionality (HashMap)

4. Fresh assignment
Develop Customer Management System , for following operations
4.1 Customer : name,email(PK), password , plan (enum :
SILVER,GOLD,DIAMOND,PLATINUM) , dob (LocalDate), reg amount (double)

4.2 CustomerHandlingException

HashMap<String,Customer>
Create a CustomerManagementSystem : a Tester , with skeleton code

Options
1. Register new customer
i/p : email
validate (containsKey) -- throw custom exc
accept remaining i/ps
add the entry in the map(put)

2. Customer Login
I/P : email & password
Throw custom exception , in case of invalid login
else : display successful login message
Hint : CollectionUtils :class
Add a static method for user login
public static Customer authenticateCustomer(em,pass,map) ....
{
1. get --null => invalid email : throw custom exc
2. not null : Customer --getPassword --equals --valid or throw exc : invalid pwd
}

3. Change Password
I/P : email , old password , new password
Throw custom exception , in case of invalid login
In case of valid login , change password
Hint : authenticateCustomer ---success --setter for pwd

4. Un subscribe customer
I/P : email
Throw custom exception , in case of invalid email , otherwise , delete customer
information.
Hint : map.remove(email)

5. Display all registered customer details


Hint : map---> collection view(values) : Collection<Customer> --for-each

6. Display names of all customers who have chosen a specific plan


i/p : plan
Hint : map--> Collection (values) --for-each --filter

7. Display senior citizen details (i.e customer age > 60 yrs)


no i/ps
Hint : map--> collection --> for-each
API : java.time.Period --between , getYears

Day17
1. Complete pending assignemnts
2. Import day17.1 , to revise CRUD operations , searching , sorting in maps.

3. Import day17.2 , to revise Java 8 new features


default , static methods in i/f
Functional i/f
Using Lambda expression in higher order function.

4. Try this , in continuation of yesterday's customer management system.


4.1 Remove all customer details , under specified plan , born after specific date.
I/P : plan n date
Initially try this in imperative style n then replace it by functional prog style.

4.2 Display customer details , sorted as per dob , using custom ordering.

4.3 Display customer details , sorted as per email (asc order)

You might also like