0% found this document useful (0 votes)
336 views10 pages

OpenXava Food Menu Application Guide

1. The document provides instructions over multiple days for learning Java. 2. It includes tasks like completing installations, reading documentation, coding samples, assignments on classes, inheritance, polymorphism and more. 3. Key tasks are to create classes like Point2D, Box, Fruit classes in inheritance hierarchy and applications to test them, with options to understand OOP concepts better.

Uploaded by

pr so
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
336 views10 pages

OpenXava Food Menu Application Guide

1. The document provides instructions over multiple days for learning Java. 2. It includes tasks like completing installations, reading documentation, coding samples, assignments on classes, inheritance, polymorphism and more. 3. Key tasks are to create classes like Point2D, Box, Fruit classes in inheritance hierarchy and applications to test them, with options to understand OOP concepts better.

Uploaded by

pr so
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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\[Link]

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
[Link] 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 :


[Link]
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)
{
[Link]=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: [Link]: " + [Link]() +
", [Link]: " + [Link]());//10 20
t1 = t2;
s.o.p("2: [Link]: " + [Link]() +
", [Link]: " + [Link]());//20 20
[Link](27);
s.o.p("3: [Link]: " + [Link]() +
", [Link]: " + [Link]());//27 27
[Link]([Link]()+10);
s.o.p("4: [Link]: " + [Link]() +
", [Link]: " + [Link]());//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 [Link]

3.1 Create Cube


[Link]
sop("Enter side of a cube");
Box abc=new Box([Link]());
sop("vol of cube "+[Link]());
[Link] : 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=[Link](b2);
if(status)
sop("SAME");
else
sop("DIFFERENT");

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


boolean checkEquality(Box anotherBox)
{
return [Link]==[Link] && .......;
}

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=[Link](.....);//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
[Link]() ... [Link]() --- 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\[Link]
cd..\bin
java [Link]

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"
[Link]
(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 - "[Link]" : 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 : [Link](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 [Link] class methods --sqrt, pow etc.
eg : public double calculateDistance(Point2D anotherPoint)
{
[Link](.....);
}

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.

[Link] 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 "[Link]" below src
3.3 Create a class "[Link]" 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[[Link]()];
3.6 Prompt user for x & y co ordinates n store the data suitably (How )
for loop
for(int i=0;i<[Link];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=[Link]();
int end=[Link]();
//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 "[Link]"


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 "[Link]"
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 [Link]

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 "+[Link]()+" 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 [Link]
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 [Link]
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
[Link]

2. import day15.2 n revise LinkedHashSet n TreeSet

3. From day15.2 , [Link]


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 : [Link](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 : [Link] --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)

Common questions

Powered by AI

The application should first display a menu with different food items assigned fixed prices. Establish a loop where users can select an item by entering the corresponding number, specify the quantity, and continue choosing items. Use a switch statement to handle user input regarding menu choices. Accumulate the total cost as users make selections. When the user selects the 'Generate Bill' option, break the loop and display the total bill. Ensure the program implements proper input validation to handle unexpected or erroneous input gracefully .

The "Box" class can be enhanced by adding specific methods. First, implement a constructor that accepts dimensions directly to create a cube. For comparing two boxes, introduce a method like 'checkEquality' that checks if all dimensions of two boxes are exactly the same. To modify dimensions, add a method such as 'createNewBox', which applies offsets supplied by the user and returns a new Box object. Finally, to determine volume versatility, provide a method that calculates and compares the volumes of two boxes to display additional characteristics, such as the box color with the larger volume .

Implement a base Employee class with common attributes such as id, name, departmentId, and basic salary, with methods to return employee details. Extend this class into Manager and Worker subclasses, adding specific fields like performanceBonus for Managers and hoursWorked and hourlyRate for Workers. Override the toString method for detailed outputs, compute net salaries with unique formulas for Managers and Workers. Incorporate an inheritance hierarchy to facilitate polymorphism where operations like fetching employee details or computing salaries become more streamlined using a single for-each loop. Employ comprehensive type checks to enhance method reliability .

First, define a base class 'Fruit' with attributes for color and weight, typically encapsulated with private access modifiers. Implement a 'taste' method returning a generic taste description like 'no specific taste'. Then, create subclasses for 'Apple', 'Orange', and 'Mango', each overriding the taste method to reflect unique descriptions: 'sweet n sour', 'sour', and 'sweet', respectively. Include any additional methods specific to each fruit, such as 'jam', 'juice', and 'pulp' for Apple, Orange, and Mango. This setup demonstrates polymorphism where each subclass provides specific implementations for a behavior defined in a parent class .

To enforce a unique identifier system, modify the equals method in the Employee class to include comparisons of empId, deptId, and joinDate. Also, customize the hashCode method to reflect these fields for consistent usage in hash-based collections. When instantiating an employee, ensure the constructor initializes empId, deptId, and joinDate accordingly. Such changes require validation logic in employee comparisons, effectively managing objects in collections where uniqueness and identity are central. Adjust validation routines to incorporate these attributes, maintaining data integrity across organization management applications .

First, use the Scanner class in Java for taking input from the user. After accepting the two double values, verify if both numbers are integers by casting them to integers and checking if the casted values relate back to the original double values. If they do not match, it indicates that the input is not an integer, hence output an appropriate error message and terminate the program. Else, compute the average of the two numbers and print it .

Implement a data structure like HashMap to store customer information using email as the key. For registration, check if the email already exists; if so, throw a custom exception, otherwise, proceed with data insertion. During login, authenticate with provided email and password, throwing exceptions for invalid attempts. For password changes, validate login credentials beforehand and utilize a setter method to update the password. To manage subscriptions, validate email presence for deletion operations, using exceptions for error handling. Ensure robust exception handling for better user interaction and security across system operations .

Leverage Java's TreeSet in conjunction with a custom Comparator to achieve the desired ordering based on GPA. Begin by collecting student details, ensuring uniqueness through proper implementation of the equals and hashCode methods. In the custom Comparator, define logic to compare Student objects' GPA, sorting them accordingly in the TreeSet. This approach not only applies specific ordering criteria but also utilizes the set's properties to maintain sorted order automatically, providing an elegant and efficient solution for displaying sorted student details. Consider using lambda expressions for concise Comparator implementations .

Design the Point2D class by including private members for x and y coordinates, initialized through a parameterized constructor. Implement a method 'getDetails' that returns a string with the point's coordinates for display purposes. For equality checking, introduce an 'isEqual' method that compares the x and y coordinates of the current instance with another Point2D object, returning true if they match. To support distance calculation, provide a 'calculateDistance' method that utilizes the distance formula utilizing Math.sqrt and Math.pow, thereby determining and returning the Euclidean distance between the current point and a specified point .

Utilize the Map's ability to store customer entries with quick retrievals by keeping email as a key. To query customers by plan, iterate over the collection view of values (customers), filtering those matching the input plan. For displaying senior citizens, use Java's date-time API to compute ages from stored 'dob', filtering customers older than 60 years. These techniques leverage the Map's efficiency in handling large datasets, providing reliable and fast query processing based on certain attributes or conditions .

You might also like