Core Java Assignments
Core Java Assignments
1. Accept 2 numbers as command line arguments from user. If user supplies less t
han 2 arguments supply error message & terminate. .If all correct, compute avara
ge & display the same.
2. Accept any no of arguments from user as command line args.Display these argum
ents in reverse manner.
Day 2
3. Display food menu to user. User will select items from menu along with the qu
antity. (eg 1. Dosa 2. Samosa .......10 . Generate Bill ) When user enters 'Gene
rate Bill' option, display total bill & exit.
2.1.Consider the following. What will happen? MUST understand with memory diagra
ms.
class Tank {
private int level;
Tank(int l)
{
level=l;
}
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());
t1 = t2;
s.o.p("2: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());
t1.setLevel(27);
s.o.p("3: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());
t2.setLevel(t1.getLevel()+10);
s.o.p("4: t1.level: " + t1.getLevel() +
", t2.level: " + t2.getLevel());
}
}
2. Create Java Application for the following .
Create Point class Point2D in package "geom" : for representing a point in x-y
co-ordinate system.
2.1Create a parameterized constructor to accept x & y co-ords.
Add show method to Point2D class : to return the x & y coords .(public String s
how())
2.2 Add isEqual method to Point2D class : boolean returning method : must ret. t
rue if both points are having same x,y co-ords or false otherwise. :
2.3 Add a method to Point2D class -- to create and return new point having given
x & y offset.
(eg Point createNewPoint(int xOffset,int yOffset))
2.4 Write TestPoint class with a main method in the separate package "tester"
2.5 Create 2 points by taking data from user. Use show method to display the coords of 2 points.
2.6 Use isEqual method : to chk the equality of 2 points.
2.7 Accept x offset & y offset from user & call createNewPoint method.Display x,
y co-ords of new point.
2.8 Create TestPoints class with main method.
Prompt user for --no of points to be created.
Create suitable array & store points.
Display all points.
Display the value of largest x-coord & y-coord.
Day 3
1. Complete all earlier assignments & revise
method overloading vs method overriding
2.
Apply inheritance & polymorphism to organization scenario
Create Emp based org structure in package com.app.dmc
---having classes Emp , Mgr and Worker
Emp state--- id(primary key-unique), name, deptId , basic
Behaviour --- get emp details --by overriding toString
Mgr state ---id,name,basic,dept,perfBonus
Behaviour ----get mgr details, compute net salary (formula: basic+perfBonus)
& getter for performance bonus.
Worker state ---id,name,basic,dept, hoursWorked,hourlyRate
Behaviour--- get worker details, compute net salary (formula: = basic+(hrs*rate
)
getter hrlyRate of the worker
Design classes based on above info.
Create a TestOrg class in tester package to create org structure having 2 manag
ers & 2 workers.
Display all employee details & net salary , from single for-each loop.
Day 4
1.Create Java application for fixed stack & growable stack of employees function
ality.
1.1 Create Employee class -- id,name, constructor,toString
1.2 Stack interface -- push & pop functionality for Emp refs.
1.3 Create implementation class -- FixedStack
1.4 Create implementation class -- GrowableStack
1.5