100% found this document useful (2 votes)
618 views

Java Mandatory 1.1 To 7

The document describes a problem to write a Java program to display item details like type, cost per day, and deposit amount for an International Film Festival. It provides specifications to create separate classes - ItemType class with private member variables for name and cost, and a DisplayItem class with a method to get input and display output in a specified format. The classes and method names, variable types, and object-oriented approach must be followed as per the given problem statement.

Uploaded by

naga rajan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
618 views

Java Mandatory 1.1 To 7

The document describes a problem to write a Java program to display item details like type, cost per day, and deposit amount for an International Film Festival. It provides specifications to create separate classes - ItemType class with private member variables for name and cost, and a DisplayItem class with a method to get input and display output in a specified format. The classes and method names, variable types, and object-oriented approach must be followed as per the given problem statement.

Uploaded by

naga rajan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 77

Basic Elements of Java / Practice / Mandatory

Customized Welcome Message


 
William, the founder of “Pine Tree” company wished to design an Event Management System that
would let its Customers plan and host events seamlessly via an online platform.
 
As a part of this requirement, William wanted to write a piece of code for his company’s Event
Management System that will display customized welcome messages by taking the Customer's name
as input. Write a program to achieve William’s task.
 
Input Format:

The first line of the input is a string that corresponds to a Customer’s name.


[Note: The maximum length of the input string is 50]

Output Format:

The output should display the welcome message along with the Customer’s name.
Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]

Sample Input and Output:

Enter your name


Chloe
Hello Chloe! Welcome to Event Management System.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// your code here

String name;

Scanner sc=new Scanner(System.in);

System.out.println("Enter your name");

name=sc.next();

System.out.println("Hello"+" "+name+"! Welcome to Event Management System.");

}
}
Total Expenses for the Event
 
The prime functionality of an Event Management System is budgeting. An Event Management System
should estimate the total expenses incurred by an event and the percentage rate of each of the
expenses involved in planning and executing an event. William, the founder of "Pine Tree" wanted to
include this functionality in his company’s Event Management System.
 
Write a program to get the branding expenses, travel expenses, food expenses, and logistics
expenses as inputs from the user and calculate the total expenses for an event and the percentage
rate of each of these expenses.
 
Note :
Formula to calculate percentage = ( Expenses to be found/Total expenses )*100 

Input Format:

The first input is a Double value that corresponds to the branding expenses.
The second input is a Double value that corresponds to the travel expenses.
The third input is a Double value that corresponds to the food expenses.
The fourth input is a Double value that corresponds to the logistics expenses.
 
Output Format:

The first line of the output should display the double value that corresponds to the total expenses for
the Event.
The next four lines should display the percentage rate of each of the expenses.
All the double values should be displayed upto 2 decimal places.
Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]

Sample Input and Output:

Enter branding expenses


20000
Enter travel expenses
40000
Enter food expenses
15000
Enter logistics expenses
25000
Total expenses: Rs.100000.00
Branding expenses percentage: 20.00%
Travel expenses percentage: 40.00%
Food expenses percentage: 15.00%
Logistics expenses percentage: 25.00%
import java.util.*;

import java.io.*;

public class Main{

public static void main(String[] args) throws Exception{

// Filldoub your code

double brand,travel,food,log,total;

double bp,lp,fp,tp;

Scanner sc=new Scanner(System.in);

System.out.println("Enter branding expenses");

brand=sc.nextDouble();

System.out.println("Enter travel expenses");

travel=sc.nextDouble();

System.out.println("Enter food expenses");

food=sc.nextDouble();

System.out.println("Enter logistics expenses");

log=sc.nextDouble();

total=(brand+travel+food+log);

bp=(brand/total)*100;

tp=(travel/total)*100;

fp=(food/total)*100;

lp=(log/total)*100;
System.out.println("Total expenses: Rs."+String.format("%.2f",total));

System.out.println("Branding expenses percentage: "+String.format("%.2f",bp)+"%");

System.out.println("Travel expenses percentage: "+String.format("%.2f",tp)+"%");

System.out.println("Food expenses percentage: "+String.format("%.2f",fp)+"%");

System.out.println("Logistics expenses percentage: "+String.format("%.2f",lp)+"%");

Thrill ride
 
"Zebra Kingdom" is a brand new Amusement park that is going to be inaugurated shortly in the City
and is promoted as the place for breath-taking charm. The theme park has more than 30 exhilarating
and thrilling rides and as a special feature of the park, the park Authorities have placed many Booking
Kiosks at the entrance which would facilitate the public to purchase their entrance tickets and ride
tickets.
 
There are few rides in the park that are not suitable for children and aged people, hence the park
Authorities wanted to program the kiosks to issue the tickets based on people’s age. If the age given
is less than 15 (Children) or greater than 60 (Aged), then the system should display as " Not Allowed",
otherwise it should display as "Allowed".
Write a program to implement this functionality.
 
Input Format:

The first line of the input is an integer that corresponds to the age of the person opting for the ride.

Output Format:

The output should display "Allowed" or "Not Allowed" based on the conditions given.
Refer sample input and output for formatting specifications.

Sample Input 1:

20

Sample Output 1:

Allowed

Explanation:

20 is greater than 15, so the output is “Allowed”

Sample Input 2:
12

Sample Output 2:

Not Allowed

Explanation:

12 is less than 15, so the output is “Not Allowed”

import java.util.*;

import java.io.*;

class Main{

public static void main(String[] args) throws Exception{

// Fill your code

int age;

Scanner sc=new Scanner(System.in);

age=sc.nextInt();

if(age<15 || age>60)

System.out.println("Not Allowed");

else

System.out.println("Allowed");

}
Star Pattern
Write a program to generate a pattern of stars.

 
Input and Output Format:
Input consists of a single integer that corresponds to n, the number of rows.
Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to the output.]

Sample Input and Output 1:


5
*
**
***
****
*****
 

Sample Input and Output 2:


3
*
**
***

import java.util.*;

import java.io.*;

class Main{

public static void main(String[] args) throws Exception{

// Fill your code

int n,i,j;

Scanner sc=new Scanner(System.in);

n=sc.nextInt();

for(i=1;i<=n;i++)

for(j=1;j<=i;j++)

System.out.print("*");
}

System.out.println(" ");

Hazecraft Client Series 


 
The Event Organizing Company "Hazecraft" focuses on event management in a way that creates a
win-win situation for all involved stakeholders. Hazecraft doesn't look at building one time associations
with clients but aim at creating long-lasting collaborations that will span years to come. This goal of
the company has helped them to evolve and gain more clients within a notable time.
The number of clients of the company from the start day of their journey till now is recorded sensibly
and is seemed to have followed a specific series like 2,3,5,7,11,13,17,19, 23,…, etc
 
Write a program that takes an integer N as the input and will output the series till the Nth term.
 
Note:
The given series is prime number series.
 
Input Format:

The first line of the input is an integer N.

Output Format:

The output is a single line series till Nth term, each separated by a space.
Refer sample input and output for formatting specifications.

Sample Input 1:

Sample Output 1:

2 3 5 7 11

Sample Input 2:

10

Sample Output 2:

2 3 5 7 11 13 17 19 23 29
import java.util.*;

public class Main{

public static void main(String[] args){

int c=0,i=1,j=1,n=0,p;

Scanner sc=new Scanner(System.in);

p=sc.nextInt();

while(n<p)

j=1;

c=0;

while(j<=i)

if(i%j==0)

c++;

j++;

if(c==2)

System.out.printf("\t%d",i);

n++;

i++;

//Fill your code

}
OOPS, Classes & Methods / Practice / Mandatory

Display Item Type


The International Film Festival of India (IFFI), founded in 1952, is one of the most significant film
festivals in Asia. The festival is for a week and arrangements have to be made for food, chairs, tables,
etc. The organizing committee plans to deposit the advance amount to the contractors on confirmation
of booking.

Write a Java program to get item type, cost per day, and deposit amount from the user and display
these details in a detailed view using the following classes and methods.
 
[Note :Strictly adhere to the object-oriented specifications given as a part of the problem
statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]

Consider a class named ItemType.


It must have the following private member variables/attributes.
 
Data Type Variable
String name
Double costPerDay
Double deposit

Include the appropriate getters and setters.

The ItemType class includes the following method.


 
Method name Description
This method should display ‘Item type details’ followed by the details of the ItemType in the format as
public void display()
 
Consider the class Main. It includes the method main
Write a code in the main method to test the ItemType class.
The following must be done inside the main method to test the ItemType class.
 Get the item type details as input.
 Create an ItemType Object with the given details using the setters of ItemType and call the display( )
method.
 The itemType details need to be displayed in the display() method
 

Please use the below sample convention to create getters and setters of the class ItemType
private String name;
public String getName( ) {
        return name;
}
public void setName(String name) {
        this.name = name;
}

Input and Output Format:


Refer sample input and output for formatting specifications.
Note:
Cost per day and Deposit value should be displayed up to 2 decimal places.

[All text in bold corresponds to input and the rest corresponds to output.]

Sample Input and Output 1:


Enter the item type name
Catering
Enter the cost per day
25000.00
Enter the deposit
10000.50
Item type details
Name : Catering
CostPerDay : 25000.00
Deposit : 10000.50

MAIN.JAVA

import java.io.*;
import java.util.*;
class Main{
public static void main(String[] args) throws Exception{

//Fill your code


Scanner sc=new Scanner(System.in);
String nm;
double cpd,d;
System.out.print("Enter the item type name");
nm=sc.nextLine();
System.out.println("Enter the cost per day");
cpd=sc.nextDouble();
System.out.println("Enter the deposit");
d=sc.nextDouble();
ItemType it=new ItemType();
if(cpd<0||d<0)
{
System.out.println("Invalid Input");

}
else{

it.setName(nm);
it.setCostPerDay(cpd);
it.setDeposit(d);
it.display();
}
}
}

ITEM.TYPE.JAVA

import java.text.*;

public class ItemType {

//Fill your code


private String name;
private double costPerDay;
private double deposit;

public String getName() {


return name;
}
public void setName(String name) {
this.name=name;
}

public double getCostPerDay() {


return costPerDay;
}
public void setCostPerDay(double costPerDay) {
this.costPerDay=costPerDay;
}
public double getDeposit() {
return deposit;
}
public void setDeposit(double deposit) {
this.deposit=deposit;
}
public void display(){

//Fill your code


System.out.println("Item type details");
System.out.println("Name : "+name);
System.out.printf("CostPerDay : %.2f\n",costPerDay);
System.out.printf("Deposit : %.2f",deposit);

}
}
 

Compare Phone Number


New App helps you discover great places to eat around or de-stress in all major cities across 20000+
merchants. Explore restaurants, spa & salons, and activities to find your next fantastic deal. Write a
program to find the duplication of user accounts.

Write a Java program to get two users’ details and display whether their phone numbers are the same
or not with the following class and methods.

[Note: Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]

Consider the class User with the following private attributes/variables.


Date Type Variable
String     name
String     username
String     password
Long     phoneNumber

Include appropriate getters and setters.


Prototype for the Parameterized Constructor,
public User(String name, String username, String password, Long phoneNumber)

Define the following method in the User class.


Method Name   Description
public boolean comparePhoneNumber(User user) In this method, compare the phone number of the two users and

Consider the Main class and write the main method to test the above class.

In the main method


     Obtain the details of the user.
     Create an object for the User class using the parameterized constructor(name, username,
password, phoneNumber).
     Call the method comparePhoneNumber() in the Main class.
 

The link to download the template code is given below


Code Template

Input and Output Format

Refer sample input and output for formatting specifications.


If both phone numbers are the same then print “Same Users” else print “Different Users”.
The output should be printed in the Main class.

Sample Input/Output 1:
[All text in bold corresponds to the input and the rest corresponds to output.]

Enter Name
john
Enter UserName
john@123
Enter Password
john@123
Enter PhoneNumber
9092314562
Enter Name
john
Enter UserName
john@12
Enter Password
john@12
Enter PhoneNumber
9092314562
Same Users

Sample Input/Output 2:

Enter Name
william
Enter UserName
william####
Enter Password
william
Enter PhoneNumber
9092314562
Enter Name
john
Enter UserName
john@123
Enter Password
john@123
Enter PhoneNumber
9092312102
Different Users
MAIN.JAVA

import java.io.*;

import java.util.*;

class Main{

public static void main(String[] args) throws Exception{


//Fill your code

String i,j,k;long l;

String i2,j2,k2;long l2;

boolean b;

Scanner sc=new Scanner(System.in);

System.out.println("Enter Name");

i=sc.next();

System.out.println("Enter UserName");

j=sc.next();

System.out.println("Enter Password");

k=sc.next();

System.out.println("Enter PhoneNumber");

l=sc.nextLong();

System.out.println("Enter Name");

i2=sc.next();

System.out.println("Enter UserName");

j2=sc.next();

System.out.println("Enter Password");

k2=sc.next();

System.out.println("Enter PhoneNumber");

l2=sc.nextLong();

User u=new User(i,j,k,l);

User u2=new User(i2,j2,k2,l2);

b=u.comparePhoneNumber(u2);

if(b==true)

System.out.println("Same"+" "+"Users");

else

System.out.println("Different"+" "+"Users");

}
USER.JAVA

public class User {

//Fill your code

private String name,username,password;

private long phoneNumber;

boolean flag = false;

public User(String name,String username,String password,long phoneNumber)

this.name=name;

this.username=username;

this.password=password;

this.phoneNumber=phoneNumber;

public boolean comparePhoneNumber(User user)

//Fill your code

flag=(user.phoneNumber==phoneNumber);

return flag;

RECTANGLE DIMENSION CHANGE - INSTANCEOF OPERATOR

Rectangle Dimension Change


 
Write a Java program to illustrate the method of returning objects by getting details from the user and
check the type of objects using instanceof and display these details in a detailed view using the
following classes and methods.

[Note :
Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned. Create separate classes in separate files.]

Consider a class Rectangle with the following private member variables/attributes.


 
Data Type Variable
Integer length
Integer width

Include appropriate getters and setters.


Prototype for the Parameterized Constructor,
public Rectangle(Integer length, Integer width)

The Rectangle class includes the following methods.


 
Method Name Description
Integer area( ) This method computes the area of the rectangle and returns
void display( ) This method displays the length and width of the rectangle
Rectangle dimensionChange(Integer newDimension) This method changes the rectangle dimension by increasin
 
Consider the class Main and write a main() method to test the above class.

In the main( ) method,


 
 Display the area of the rectangle inside the main() method.
 Obtain the details of the user.
 Create an object for the Rectangle class using the parameterized constructor(length, width).
Problem Constraints:

Use instanceof operator to check the object returned by dimensionChange( ) method.


[The java instanceof operator is used to test whether the object is an instance of the specified type
(class or subclass or interface).]

The link to download the template code is given below


Code Template

Input and Output Format:


Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output.]

Sample Input and Output :

Enter the length of the rectangle


5
Enter the width of the rectangle
6
Rectangle Dimension
Length:5
Width:6
Area of the Rectangle:30
Enter the new dimension
2
Rectangle Dimension
Length:10
Width:12
Area of the Rectangle:120

Problem Requirements:
Java
Keyword Min Count Max Count

instanceof 1 -

RECTANGULAR.JAVA

public class Rectangle {

//Fill your code

private int length,width;

public Rectangle(int length,int width)

this.length=length;

this.width=width;

public void setLength(int length)

this.length=length;

public int getLength()

return length;

public void setWidth(int width)

this.width=width;

public int getWidth()

return width;

}
public Integer area() {

//Fill your code

int a=length*width;

return a;

public void display(){

//Fill your code

System.out.println("Rectangle Dimension");

System.out.println("Length:"+length+"\nWidth:"+width);

//System.out.println("Area of the Rectangle:"+area());

Rectangle dimensionChange(Integer newDimension){

Rectangle rectangleObject = this;

//Fill your code

setLength(rectangleObject.length*newDimension);

setWidth(rectangleObject.width*newDimension);

return rectangleObject;

MAIN.JAVA

import java.io.*;
import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception, IOException {

//Fill your code

int l,w,d,a;

Scanner sc=new Scanner(System.in);

Rectangle r1,r2;

System.out.println("Enter the length of the rectangle");

l=sc.nextInt();

System.out.println("Enter the width of the rectangle");

w=sc.nextInt();

r1=new Rectangle(l,w);

r1.display();

a=r1.area();

System.out.println("Area of the Rectangle:"+a);

System.out.println("Enter the new dimension");

d=sc.nextInt();

r2=r1.dimensionChange(d);

if(r2 instanceof Rectangle)

r2.display();

a=r2.area();

System.out.println("Area of the Rectangle:"+a);

}
Array

Write a Java program to display the array of Integers and array of Strings. Use for each loop to iterate
and print the elements.
 
Constraints :
Use for each loop to iterate and print the elements.
 
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output :


 
Enter n :
3
Enter numbers : 
100
23
15
Enter strings : 
hi
hello
welcome
Displaying numbers
100
23
15
Displaying strings
hi
hello
welcome

Problem Requirements:

Java
Keyword Min Count Max Count

for 1 4

MAIN.JAVA

import java.io.*;

import java.util.*;

public class Main{

public static void main (String[] args) throws Exception{

//Fill your code


Scanner sc=new Scanner(System.in);

int n;

System.out.println("Enter n :");

n=sc.nextInt();

int [] num = new int[n];

String [] a = new String[n];

System.out.println("Enter numbers :");

for(int i=0; i<n; i++ ) {

num[i] = sc.nextInt();

System.out.println("Enter strings :");

for(int j=0; j<n; j++ ) {

a[j] = sc.next();

System.out.println( "Displaying numbers");

for(int numbers: num)

System.out.println(numbers);

System.out.println("Displaying strings");

for(String letters: a)

System.out.println(letters);

Command Line Argument - Count


Write a program to accept strings as command-line arguments and print the number of arguments
entered.

Sample Input (Command Line Argument) 1:


Command Arguments

Sample Output 1:
Arguments :
Command
Arguments
The number of arguments is 2
 

Sample Input (Command Line Argument) 2:


Commands

Sample Output 2:
Arguments :
Commands
The number of arguments is 1

MAIN.JAVA

import java.io.*;

import java.util.*;

public class Main{

public static void main (String[] args) throws Exception{

//Fill your code

int l=args.length;

System.out.println("Arguments :\n");

for(int i=0;i<l;i++)

System.out.println(args[i]);

System.out.println("The number of arguments is "+l);

Inheritance / Practice / Mandatory

Single inheritance
Write a Java program to implement Single Inheritance.

[Note: Strictly adhere to the object oriented specifications given as a part of the problem statement. Use
the same class names and member variable names.
Follow the naming conventions mentioned for getters/setters]  

Consider a class named Person with the following private data members.


                           
Data Type     Data Member   
String name
String dateOfBirth
String gender
String mobileNumber
String bloodGroup

Include appropriate getters and setters.

Consider a class named Donor which extends Person class with the following private data members.
 
Data Type     Data Member   
String bloodBankName
String donorType
String donationDate

Include appropriate getters and setters.

The class Donor should have the following method


 
Method Description
This method displays the donation details.
public void displayDonationDetails( )
Display the statement ‘Donation Details :’ inside this method

Consider another class Main and write the main method to test the above class.

In the main( ) method, read the person and donor details from the user and call the
displayDonationDetails( ) method.

[Note: The date format should be “dd-MM-yyyy”]

The link to download the template code is given below


Code Template

Input and Output Format:

Refer sample input and output for formatting specifications.


All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:


 
Enter the name :
Justin
Enter Date of Birth :
11-01-1995
Enter Gender :
Male
Enter Mobile Number :
9994910354
Enter Blood Group :
B+ve
Enter Blood Bank Name :
Blood Assurance
Enter Donor Type :
Whole Blood
Enter Donation Date :
09-07-2017
Donation Details :
Name : Justin
Date Of Birth : 11-01-1995
Gender : Male
Mobile Number : 9994910354
Blood Group : B+ve
Blood Bank Name : Blood Assurance
Donor Type : Whole Blood
Donation Date : 09-07-2017

Sample Input and Output 2:


 
Enter the name :
Steffie
Enter Date of Birth :
12-01-1996
Enter Gender :
Female
Enter Mobile Number :
8868875432
Enter Blood Group :
O+ve
Enter Blood Bank Name :
Edward Blood Bank
Enter Donor Type :
Whole Blood
Enter Donation Date :
21-12-2016
Donation Details :
Name : Steffie
Date Of Birth : 12-01-1996
Gender : Female
Mobile Number : 8868875432
Blood Group : O+ve
Blood Bank Name : Edward Blood Bank
Donor Type : Whole Blood
Donation Date : 21-12-2016
 

MAIN.JAVA

import java.io.*;

import java.util.Scanner;

public class Main {

public static void main(String[] args){

Scanner sc=new Scanner(System.in).useDelimiter("\n");

System.out.println("Enter the name :");

String name=sc.nextLine();
System.out.println("Enter Date of Birth :");

String dateOfBirth=sc.nextLine();

System.out.println("Enter Gender :");

String gender=sc.nextLine();

System.out.println("Enter Mobile Number :");

String mobileNumber=sc.nextLine();

System.out.println("Enter Blood Group :");

String bloodGroup=sc.nextLine();

System.out.println("Enter Blood Bank Name :");

String bloodBankName=sc.nextLine();

System.out.println("Enter Donor Type :");

String donorType=sc.nextLine();

System.out.println("Enter Donation Date :");

String donationDate=sc.nextLine();

Donor donor=new Donor();

donor.setName(name);

donor.setDateOfBirth(dateOfBirth);

donor.setGender(gender);

donor.setMobileNumber(mobileNumber);
donor.setBloodGroup(bloodGroup);

donor.setBloodBankName(bloodBankName);

donor.setDonorType(donorType);

donor.setDonationDate(donationDate);

donor.displayDonationDetails();

PERSON.JAVA

class Person{

public String name,dateOfBirth,gender,mobileNumber,bloodGroup;

public String getName()

return name;

public void setName(String name)

this.name=name;

public String getDateOfBirth()

return dateOfBirth;

public void setDateOfBirth(String dateOfBirth)

this.dateOfBirth=dateOfBirth;
}

public String getGender()

return gender;

public void setGender(String gender)

this.gender=gender;

public String getMobileNumber()

return mobileNumber;

public void setMobileNumber(String mobileNumber)

this.mobileNumber=mobileNumber;

public String getBloodGroup()

return bloodGroup;

public void setBloodGroup(String bloodGroup)

this.bloodGroup=bloodGroup;

DONOR.JAVA

class Donor extends Person {

private String bloodBankName,donorType,donationDate;


public String getBloodBankName()

return bloodBankName;

public void setBloodBankName(String bloodBankName)

this.bloodBankName=bloodBankName;

public String getDonorType()

return donorType;

public void setDonorType(String donorType)

this.donorType=donorType;

public String getDonationDate()

return donationDate;

public void setDonationDate(String donationDate)

this.donationDate=donationDate;

public void displayDonationDetails()

System.out.println("Donation Details :");

System.out.println("Name :"+name);

System.out.println("Date Of Birth :"+dateOfBirth);

System.out.println("Gender : "+gender);

System.out.println("Mobile Number : "+mobileNumber);


System.out.println("Blood Group : "+bloodGroup);

System.out.println("Blood Bank Name : "+bloodBankName);

System.out.println("Donor Type : "+donorType);

System.out.println("Donation Date : "+donationDate);

Calculate Reward Points

ABC Bank announced a new scheme of reward points for a transaction using an ATM card. Each
transaction using the normal card will be provided 1% of the transaction amount as a reward point. If a
transaction is made using a premium card and it is for fuel expenses, additional 10 points will be
rewarded. Write a java program to calculate the total reward points.

[Note:  Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned]

Consider a class VISACard with the following method.


 
Method Description
public Double computeRewardPoints(String type, Double amount) This method returns the 1% of the tr

Consider a class HPVISACard which extends VISACard class and overrides the following method.


 
Method Description
public Double computeRewardPoints(String type, Double amount) In this method, calculate the reward poin

Hint:
Use super keyword to calculate reward points from base class.

Consider the Main class with the main method and read all the transaction details in the main method.
Card type will be either ‘VISA card’ or ‘HPVISA card’. Otherwise, display ‘Invalid data’

Calculate the reward points corresponding to the card type and transaction type and print the reward
points(upto two decimal places).

The link to download the template code is given below


Code Template
Input and Output Format:

Refer sample input and output for formatting specifications.


Enter the transaction details in CSV format ( Transaction type, amount, card type)
All text in bold corresponds to the input and the rest corresponds to output.

Sample Input and Output 1:

Enter the transaction detail


Shopping,5000,VISA card
Total reward points earned in this transaction is 50.00
Do you want to continue?(Yes/No)
Yes
Enter the transaction detail
Fuel,5000,HIVISA card
Invalid data
Do you want to continue?(Yes/No)
Yes
Enter the transaction detail
Fuel,5000,HPVISA card
Total reward points earned in this transaction is 60.00
Do you want to continue?(Yes/No)
No

Sample Input and Output 2:

Enter the transaction detail


Fuel,1000,HPVISA card
Total reward points earned in this transaction is 20.00
Do you want to continue?(Yes/No)
No

MAIN.JAVA

import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args){

Scanner sc=new Scanner(System.in).useDelimiter("\n");

VISACard visaCard;
String contd;
do{
System.out.println("Enter the transaction detail");
String input=sc.next();
String[] inputs=input.split(",");
if(inputs[2].equals("VISA card")){
visaCard=new VISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1]));

System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward));


}
else if(inputs[2].equals("HPVISA card")){
visaCard=new HPVISACard();
double reward=visaCard.computeRewardPoints(inputs[0],Double.parseDouble(inputs[1]));

System.out.println("Total reward points earned in this transaction is "+String.format("%.2f",reward));


}
else{
System.out.println("Invalid data");
}
System.out.println("Do you want to continue?(Yes/No)");
contd=sc.next();

}
while(contd.equalsIgnoreCase("Yes"));
}
}

HPVISACARD.JAVA

class HPVISACard extends VISACard{


String type;
Double amount;
public Double computeRewardPoints(String type, Double amount)
{
double point=super.computeRewardPoints(type, amount);
if(type.equalsIgnoreCase("Fuel"))
{
double points=point+10;
return points;
}
else
{
return point;
}

}
}

VISACARD.JAVA

public class VISACard


{
String type;
Double amount;

public Double computeRewardPoints(String type, Double amount){


amount=0.01*amount;
return amount;
}

GST Calculation
Write a program to calculate the total amount with GST for the events. The Events are Stage show
and Exhibition. For the Stage show, GST will be 15% and for exhibition, GST will be 5%.

[Note: Strictly adhere to the object oriented specifications given as a part of the problem statement.
Follow the naming conventions as mentioned]

Consider class Event with the following protected attributes/variables.


 
Data Type Variable
String name
String type
Double costPerDay
Integer noOfDays

Prototype for the parametrized constructor,


public Event(String name, String type, Double costPerDay, Integer noOfDays)

Consider class Exhibition which extends the Event class with the following private attributes/variables.


 
Data Type Variable
static Integer gst = 5
Integer noOfStalls

Prototype for the parametrized constructor,


public Exhibition(String name, String type, Double costPerDay, Integer noOfDays, Integer noOfStalls)

Include appropriate getters and setters.

Include the following method.


 
Method Name Description
public Double totalCost() This method is to calculate the total amount with 5% GST

Consider class StageEvent which extends the Event class with the following private


attributes/variables.
 
Data Type Variable
static Integer gst = 15
Integer noOfSeats

Prototype for the parametrized constructor,


public StageEvent(String name, String type, Double costPerDay, Integer noOfDays, Integer noOfSeats)

Include appropriate getters and setters.

Include the following method.


 
Method Name Description
public Double totalCost() This method is to calculate the total amount with 15% GST

Override toString() method in all classes to display the event details in the format specified in sample
input and output.

Consider Main class with main method.
In the main() method, read the event details from the user and then create the object of the event
according to the event type.
The total amount will be calculated according to the GST of the corresponding event.

The link to download the template code is given below


Code Template
Input and Output Format:

Refer sample input and output for formatting specifications.


All the double values should formatted to two decimal places.
All text in bold corresponds to the input and the rest corresponds to output.

Sample Input and Output 1:

Enter event name


Sky Lantern Festival
Enter the cost per day
1500
Enter the number of days
3
Enter the type of event
1.Exhibition
2.Stage Event
2
Enter the number of seats
100
Event Details
Name:Sky Lantern Festival
Type:Stage Event
Number of seats:100
Total amount: 5175.00

Sample Input and Output 2:

Enter event name


Glastonbury
Enter the cost per day
5000
Enter the number of days
2
Enter the type of event
1.Exhibition
2.Stage Event
1
Enter the number of stalls
10
Event Details
Name:Glastonbury
Type:Exhibition
Number of stalls:10
Total amount: 10500.00

Sample Input and Output 3:

Enter event name


Glastonbury
Enter the cost per day
5000
Enter the number of days
2
Enter the type of event
1.Exhibition
2.Stage Event
3
Invalid input

MAIN.JAVA
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in).useDelimiter("\n");
System.out.println("Enter event name");
String name=sc.next();
System.out.println("Enter the cost per day");
double costPerDay=sc.nextDouble();
System.out.println("Enter the number of days");
int noOfDays=sc.nextInt();
System.out.println("Enter the type of event\n1.Exhibition\n2.Stage Event");
int type=sc.nextInt();

Event event;
if(type==1){

System.out.println("Enter the number of stalls");


int noOfStalls=sc.nextInt();
event = new Exhibition(name,"Exhibition",costPerDay,noOfDays,
noOfStalls);
System.out.println(event.toString());
}
else if(type==2){
System.out.println("Enter the number of seats");
int noOfStalls=sc.nextInt();
event = new StageEvent(name,"Stage Event",
costPerDay,noOfDays,noOfStalls);
System.out.println(event.toString());
}
else{
System.out.println("Invalid input");
}

}
}

EXHIBITION.JAVA

import java.text.DecimalFormat;

public class Exhibition extends Event {


DecimalFormat df = new DecimalFormat("#.00");
static int gst=5;
int noOfStalls;
double amt1;

public int getNoOfStalls() {


return noOfStalls;
}

public void setNoOfStalls(int noOfStalls) {


this.noOfStalls = noOfStalls;
}

public Exhibition(String name, String type, Double costPerDay, Integer noOfDays, Integer noOfStalls){
super(name,type,costPerDay,noOfDays);
this.name=name;
this.type=type;
this.costPerDay=costPerDay;
this.noOfStalls=noOfStalls;
this.noOfDays=noOfDays;
}
public Double totalCost(){
amt1 = costPerDay*noOfDays*1.05;

return amt1;
}
public String toString(){
return "Event Details\n"+"Name:"+name+"\n"+"Type:"+type+"\n"+"Number of stalls:"+noOfStalls+"\n"+"Total
amount:"+df.format(totalCost());

STAGE EVENT.JAVA

import java.text.DecimalFormat;

public class StageEvent extends Event {


private static int gst=15;
private int noOfSeats;
double amt;
DecimalFormat df = new DecimalFormat("#.00");

public int getNoOfSeats() {


return noOfSeats;
}

public void setNoOfSeats(int noOfSeats) {


this.noOfSeats = noOfSeats;
}

public static int getGst() {


return gst;
}

public static void setGst(int gst) {


StageEvent.gst = gst;
}

public StageEvent(String name, String type, Double costPerDay, Integer noOfDays, Integer noOfStalls){
super(name,type,costPerDay,noOfDays);
this.noOfSeats=noOfStalls;

}
public double totalCost(){
amt = costPerDay*noOfDays*1.15;
return amt;
}
public void display(){
System.out.println("Event Details");
System.out.println("Name:"+name);
System.out.println("Type:"+type);
System.out.println("Number of seats:"+noOfSeats);
System.out.println("Total amount:"+amt);

}
public String toString(){

return "Event Details\n"+"Name:"+name+"\n"+"Type:"+type+"\n"+"Number of seats:"+getNoOfSeats()+"\n"+"Total


amount:"+df.format(totalCost());
}

}
EVENT.JAVA

public class Event {


protected String name, type;
protected double costPerDay;
protected int noOfDays;

public Event(String name, String type, double costPerDay, int noOfDays) {


this.costPerDay = costPerDay;
this.type = type;
this.name = name;
this.noOfDays = noOfDays;

Abstract Class
 
Write a program to calculate total cost of the event based on the type of event and display details
using Abstract class and method.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names,
attribute names and method names should be the same as specified in the problem statement.

Consider an abstract class called Event with following protected attributes.


 
Attributes Datatype
name String
detail String
type String
organiser String
 
Prototype for the parametrized constructor, Event(String name, String detail, String type, String
organiser)
Include appropriate getters and setters

Include the following abstract method in the class Event.


 
Method Name Description
abstract Double calculateAmount() an abstract method

Consider a class named Exhibition which extends Event class with the following private attributes


 
Attributes Datatype
noOfStalls Integer
 rentPerStall Double
 
Prototype for the parametrized constructor,
public Exhibition(String name, String detail, String type, String organiser, Integer noOfStalls,Double
rentPerStall)
Include appropriate getters and setters
Use super( ) to call and assign values in base class constructor.

Include the following abstract method in the class Exhibition.


 
Method Name Description
Double calculateAmount () This method returns the product of noOfStalls and rentPerStall

Consider a class named StageEvent which extends Event class with the following private attributes.


 
Attribute Datatype
noOfShows Integer
costPerShow Double
Prototype for the parametrized constructor,
public StageEvent(String name, String detail, String type, String organiser, Integer noOfShows,Double
costPerShow)
Include appropriate getters and setters
Use super( ) to call and assign values in base class constructor.
 
Include the following abstract method in the class StageEvent.
 
Method Name  Description
Double calculateAmount() This method returns the product of noOfShows and costPerShow

Consider a driver class called Main. In the main method, obtain input from the user and create objects
accordingly.

The link to download the template code is given below


Code Template
Input format:
Input format for Exhibition is in the CSV format ( name,detail,type,organiser,noOfStalls,rentPerStall)
Input format for StageEvent is in the CSV
format (name,detail,type,organiser,noOfShows,costPerShow)    

Output format:
Print "Invalid choice" if the input is invalid to our application and terminate.
Display one digit after the decimal point for Double datatype.
Refer to sample Input and Output for formatting specifications.

[All text in bold corresponds to the input and rest corresponds to output]
Sample Input and output 1:
Enter your choice
1.Exhibition
2.StageEvent
1
Enter the details in CSV format
Book expo,Special sale,Academics,Martin,100,1000
Exhibition Details
Event Name:Book expo
Detail:Special sale
Type:Academics
Organiser Name:Martin
Total Cost:100000.0
Sample Input and Output 2:
 
Enter your choice
1.Exhibition
2.StageEvent
2
Enter the details in CSV format
JJ magic show,Comedy magic,Entertainment,Steffania,5,1000
Stage Event Details
Event Name:JJ magic show
Detail:Comedy magic
Type:Entertainment
Organiser Name:Steffania
Total Cost:5000.0
 
 
Sample Input and Output 3:
 
Enter your choice
1.Exhibition
2.StageEvent
3
Invalid choice
MAIN.JAVA

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner sc =new Scanner(System.in).useDelimiter("\n");
System.out.println("Enter your choice\n1.Exhibition\n2.StageEvent");
String eventType=sc.next();

Event event=null;
if(Integer.parseInt(eventType.trim())==1){
System.out.println("Enter the details in CSV format");
String input=sc.next();
String[] inputs=input.split(",");

event=new Exhibition(inputs[0].trim(), inputs[1].trim(), inputs[2].trim(), inputs[3].trim(),


Integer.parseInt(inputs[4].trim()), Double.parseDouble(inputs[5].trim()));
System.out.println("Exhibition Details");
System.out.println("Event Name:"+event.name);
System.out.println("Detail:"+event.detail);
System.out.println("Type:"+event.type);
System.out.println("Organiser Name:"+event.organiser);
System.out.println("Total Cost:"+String.format("%.1f", event.calculateAmount()));
}
else if(Integer.parseInt(eventType.trim())==2){
System.out.println("Enter the details in CSV format");
String input=sc.next();
String[] inputs=input.split(",");
event=new StageEvent(inputs[0].trim(), inputs[1].trim(), inputs[2].trim(), inputs[3].trim(),
Integer.parseInt(inputs[4].trim()), Double.parseDouble(inputs[5].trim()));
System.out.println("Stage Event Details");
System.out.println("Event Name:"+event.name);
System.out.println("Detail:"+event.detail);
System.out.println("Type:"+event.type);
System.out.println("Organiser Name:"+event.organiser);
System.out.println("Total Cost:"+String.format("%.1f", event.calculateAmount()));
}
else{
System.out.println("Invalid choice");
}

}
}

STAGE EVENT.JAVA

public class StageEvent extends Event {

//Fill your code here


private int noOfShows;
private double costPerShow;
public StageEvent(String name,String detail,String type,String organiser,int noOfShows,double costPerShow)
{
super(name,detail,type,organiser);
this.noOfShows=noOfShows;
this.costPerShow=costPerShow;
}

double calculateAmount() {

//Fill your code here

return noOfShows*costPerShow;

EXHIBITION.JAVA
public class Exhibition extends Event {

//Fill your code here


private int noOfStalls;
private double rentPerStall;
public Exhibition(String name,String detail,String type,String organiser,int noOfStalls,double rentPerStall)
{
super(name,detail,type,organiser);
this.noOfStalls=noOfStalls;
this.rentPerStall=rentPerStall;
}
int getNoOfStalls()
{
return noOfStalls;
}
double getRentPerStall()
{
return rentPerStall;
}

double calculateAmount() {

//Fill your code here

return noOfStalls*rentPerStall;
}

EVENT.JAVA

abstract public class Event{


protected String name,detail,type,organiser;
abstract double calculateAmount();

public Event(String name,String detail,String type,String organiser)


{
this.name=name;
this.detail=detail;
this.type=type;
this.organiser=organiser;
}
String getName()
{
return name;
}
String getDetail()
{
return detail;
}
String getType()
{
return type;
}
String getOrganiser()
{
return organiser;
}
//public class Event {

//Fill your code here

Overriding

 Overriding is a runtime polymorphism. The inherited class has the overridden method which has the
same name as the method in the parent class. The argument number, types, or return types should
not differ in any case. The method is invoked with the object of the specific class ( but with the
reference of the parent class).
Write a program to calculate projected revenue for exhibition and stage event using inheritance and
method overriding

[Note :
Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Use the same class names and member variable names. ]
 
Consider a parent class Event and define the following protected attributes,
Attributes Datatype
name String
detail String
ownerName String

Include appropriate getters and setters.


Prototype for the parameterized constructors to the Event class in the following order Event(String
name, String detail, String ownerName)

Declare the abstract method public abstract Double projectedRevenue() in the Event class

Consider a child class Exhibition that extends Event  that defines with the following attribute,


Attributes Datatype
noOfStalls Integer
Include appropriate getters and setters.
Prototype for the parameterized constructors to the Exhibition class in the following
order Exhibition(String name, String detail, String ownerName, Integer noOfStalls). Use super( ) to call
and assign values in the base class constructor.
Implement the abstract method projectedRevenue() in Exhibition class
MethodName Description
public Double projectedRevenue() Calculate revenue and return the double value. Each stall will produce Rs.10000 as
 

Consider another child class StageEvent that extends Event that defines with the following attribute,
Attributes Datatype
noOfShows Integer
noOfSeatsPerShow Integer
Include appropriate getters and setters.
Prototype for the parameterized constructors to the StageEvent class in the following
order StageEvent(String name, String detail, String ownerName, Integer noOfShows, Integer
noOfSeatsPerShow). Use super( ) to call and assign values in the base class constructor.
Implement the abstract method projectedRevenue() in StageEvent class
MethodName Description
public Double projectedRevenue() Calculate revenue and return the double value. Each seat produces Rs.50 revenue.

Consider the class Main. It includes the method main. In the main( ) method  the event details are
read from the user and the methods of the above classes are called

The link to download the template code is given below


Code Template
   
Input and Output Format:

Refer to sample input/output for other further details and format of the output.
The double values should be formatted to 1 decimal place.

[All Texts in bold corresponds to the input and rest are output]

Sample Input/Output 1:

Enter the name of the event:


Science Fair
Enter the detail of the event:
Explore Technology
Enter the owner name of the event:
ABCD
Enter the type of the event:
1.Exhibition
2.StageEvent
1
Enter the number of stalls:
65
The projected revenue of the event is 650000.0

Sample Input/Output 2:

Enter the name of the event:


Magic Show
Enter the detail of the event:
See Magic without Logic
Enter the owner name of the event:
SDFG
Enter the type of the event:
1.Exhibition
2.StageEvent
2
Enter the number of shows:
10
Enter the number of seats per show:
100
The projected revenue of the event is 50000.0
 

 MAIN.JAVA

import java.io.IOException;

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws IOException {


Scanner sc = new Scanner(System.in);

System.out.println("Enter the name of the event:");

String name=sc.nextLine();

System.out.println("Enter the detail of the event:");

String detail=sc.nextLine();

System.out.println("Enter the owner name of the event:");

String owner=sc.nextLine();

System.out.println("Enter the type of the event:\n1.Exhibition\n2.StageEvent");

int n=sc.nextInt();

switch (n)

case 1:

System.out.println("Enter the number of stalls:");

int stall=sc.nextInt();

Event e=new Exhibition(name,detail,owner,stall);

System.out.println("The projected revenue of the event is "+e.projectedRevenue());

break;

case 2:

System.out.println("Enter the number of shows:");

int show=sc.nextInt();

System.out.println("Enter the number of seats per show:");

int seat=sc.nextInt();

Event s=new StageEvent(name,detail,owner,show,seat);

System.out.println("The projected revenue of the event is "+s.projectedRevenue());

break;

STAGE EVENT.JAVA

class StageEvent extends Event


{

int noOfShows;

int noOfSeatsPerShow;

StageEvent(String name,String detail,String ownername,int noOfShows,int noOfSeatsPerShow)

super(name,detail,ownername);

this.noOfShows=noOfShows;

this.noOfSeatsPerShow=noOfSeatsPerShow;

public double projectedRevenue()

return noOfShows*noOfSeatsPerShow*50;

EVENT.JAVA

import java.util.*;

class Event

protected String name;protected String detail;

protected String ownername;

Event(String name,String detail,String ownername)

this.name=name;

this.detail=detail;

this.ownername=ownername;

public double projectedRevenue()

return 0.0;

}
}

EXHIBITION.JAVA

class Exhibition extends Event

int noOfStall;

Exhibition(String name,String detail,String ownername,int noOfStall)

super(name,detail,ownername);

this.noOfStall=noOfStall;

public double projectedRevenue()

return noOfStall*10000;

Interfaces and Inner Class / Practice / Mandatory

MAIN.JAVA

import java.util.*;

import java.io.*;

import java.text.*;

public class Main {

public static void main(String args[]) throws Exception{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("1.Current Account");

System.out.println("2.Savings Account");

Integer n = Integer.parseInt(br.readLine());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

switch (n) {

case 1:

System.out.println("Name");

String name = br.readLine();

System.out.println("Account Number");

String account = br.readLine();

System.out.println("Account Balance");

Double accountBalance = Double.parseDouble(br.readLine());

System.out.println("Enter the Start Date(yyyy-mm-dd)");

String sdate = br.readLine();

System.out.println("Enter the Years");

Float years = Float.parseFloat(br.readLine());

Account accountObject = new Account(name, account, accountBalance,


formatter.parse(sdate));

CurrentAccount currentAccountObject = new CurrentAccount();

Float outputValue =currentAccountObject.calculateMaintanceCharge(years);

System.out.printf("Maintenance Charge For Current Account %.2f",outputValue);

break;

case 2:

System.out.println("Name");

String name_1 = br.readLine();

System.out.println("Account Number");

String account_1 = br.readLine();

System.out.println("Account Balance");

Double accountBalance_1 = Double.parseDouble(br.readLine());


System.out.println("Enter the Start Date(yyyy-mm-dd)");

String sdate_1 = br.readLine();

System.out.println("Enter the Years");

Float years_1 = Float.parseFloat(br.readLine());

Account accountObject_1 = new Account(name_1, account_1, accountBalance_1,


formatter.parse(sdate_1));

SavingsAccount savingsAccountObject = new SavingsAccount();

Float outputValue_1 = savingsAccountObject.calculateMaintanceCharge(years_1);

System.out.printf("Maintenance Charge For Savings Account %.2f",outputValue_1);

break;

default:

System.out.println("Invalid choice");

break;

}
}

ACCOUNT.JAVA

import java.util.Date;

public class Account {

private String name;

private String accountNumber;

private double balance;

private Date startDate;

public String getName() {


return name;

public void setName(String name) {

this.name = name;

public String getAccountNumber() {

return accountNumber;

public void setAccountNumber(String accountNumber) {

this.accountNumber = accountNumber;

public double getBalance() {

return balance;

public void setBalance(double balance) {

this.balance = balance;

public Date getStartDate() {

return startDate;
}

public void setStartDate(Date startDate) {

this.startDate = startDate;

public Account(String name, String accountNumber, double balance, Date startDate) {

this.name = name;

this.accountNumber = accountNumber;

this.balance = balance;

this.startDate = startDate;

}
}

MAINTANENCE.JAVA

public interface MaintainanceCharge {

float calculateMaintanceCharge(float noOfYears);


}

CURRENT ACCOUNT.JAVA

public class CurrentAccount implements MaintainanceCharge{

public float calculateMaintanceCharge(float noOfYears) {

return 100*noOfYears+200;

}
SAVING ACCOUNT.JAVA

public class SavingsAccount implements MaintainanceCharge{


public float calculateMaintanceCharge(float noOfYears) {

return 2*50*noOfYears+50;

}
}

Interface
Write a program to display different types of Stalls by implementing interface.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names,
attribute names, and method names should be the same as specified in the problem statement.

Create an interface Stall with the following method.


Method Name Description
void display() abstract method.

Consider a class GoldStall which implements the Stall interface and define the following private
attributes.
Attribute Datatype
stallName String
cost Integer
ownerName String
tvSet Integer

Include appropriate getters and setters.


Prototype for the Parameterized Constructor,
GoldStall(String stallName, Integer cost, String ownerName, Integer tvSet).

Include the following method in the class GoldStall


Method Name Description
void display() To display the stall name, cost of the stall, owner name, and the number of tv sets.

Consider a class PremiumStall which implements the Stall interface and define the following private
attributes.
Attribute Datatype
stallName String
cost Integer
ownerName String
projector Integer

Include appropriate getters and setters.


Prototype for the Parameterized Constructor,
PremiumStall(String stallName, Integer cost, String ownerName, Integer projector) .

Include the following method in the class PremiumStall.


Method Name Description
void display() To display the stall name, cost of the stall, owner name, and the number of projectors.
Consider a class ExecutiveStall which implements Stall interface and define the following private
attributes.
Attribute Datatype
stallName String
cost Integer
ownerName String
screen Integer

Include appropriate getters and setters.


Prototype for the Parameterized Constructor,
ExecutiveStall(String stallName, Integer cost, String ownerName, Integer screen).

Include the following method in the class ExecutiveStall.


Method Name Description
void display() To display the stall name, cost of the stall, owner name, and the number of screens.

Consider the class Main. It includes the method main.


In the Main method,
 In the main( ) method, get the stall details from the user.
 Create a Stall Object with the given details and call the display( ) method.
The link to download the template code is given below
Code Template

Input Format:

The first input corresponds to choose the stall type.


The next line of input corresponds to the details of the stall in CSV format according to the stall type.

Output Format:

Print “Invalid Stall Type” if the user has chosen the stall type other than the given type
Otherwise, display the details of the stall.
Refer to sample output for formatting specifications.

Note: All Texts in bold corresponds to the input and the rest are output .

Sample Input and Output 1:

Choose Stall Type


1)Gold Stall
2)Premium Stall
3)Executive Stall
1
Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner Name, Number of TV sets)
The Mechanic,120000,Johnson,10
Stall Name: The Mechanic
Cost: Rs.120000
Owner Name: Johnson
Number of TV sets: 10

Sample Input and Output 2:


Choose Stall Type
1)Gold Stall
2)Premium Stall
3)Executive Stall
2
Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner Name, Number of Projectors)
Knitting plaza,300000,Zain,20
Stall Name: Knitting plaza
Cost: Rs.300000
Owner Name: Zain
Number of Projectors: 20

Sample Input Output 3:

Choose Stall Type


1)Gold Stall
2)Premium Stall
3)Executive Stall
3
Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner Name, Number of Screens)
Fruits Hunt,10000,Uber,7
Stall Name: Fruits Hunt
Cost: Rs.10000
Owner Name: Uber
Number of Screens: 7

Sample Input Output 4:

Choose Stall Type


1)Gold Stall
2)Premium Stall
3)Executive Stall
4
Invalid Stall Type
MAIN.JAVA

import java.util.*;

public class Main {

public static void main(String[] args){

Scanner br = new Scanner(System.in);

System.out.println("Choose Stall Type");

System.out.println("1)Gold Stall");

System.out.println("2)Premium Stall");
System.out.println("3)Executive Stall");

int type = Integer.parseInt(br.nextLine());

switch(type)

case 1:

System.out.println("Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner


Name, Number of TV sets)");

String st1=br.nextLine();

String[] str1=st1.split(",");

GoldStall gd = new
GoldStall(str1[0],Integer.parseInt(str1[1]),str1[2],Integer.parseInt(str1[3]));

gd.display();

break;

case 2:

System.out.println("Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner


Name, Number of Projectors)");

String st2=br.nextLine();

String[] str2=st2.split(",");

PremiumStall pm = new
PremiumStall(str2[0],Integer.parseInt(str2[1]),str2[2],Integer.parseInt(str2[3]));

pm.display();

break;

case 3:
System.out.println("Enter Stall details in comma-separated(Stall Name, Stall Cost, Owner
Name, Number of Screens)");

String st3=br.nextLine();

String[] str3=st3.split(",");

ExecutiveStall ex = new
ExecutiveStall(str3[0],Integer.parseInt(str3[1]),str3[2],Integer.parseInt(str3[3]));

ex.display();

break;

default:

System.out.println("Invalid Stall Type");

break;

}
}

EXECUTIVE STALL.JAVA

public class ExecutiveStall implements Stall{

private String stallName;

private int cost;

private String ownerName;

private int screen;

public ExecutiveStall(String stallName, int cost, String ownerName, int screen) {


this.stallName = stallName;

this.cost = cost;

this.ownerName = ownerName;

this.screen = screen;

public String getStallName() {

return stallName;

public void setStallName(String stallName) {

this.stallName = stallName;

public int getCost() {

return cost;

public void setCost(int cost) {

this.cost = cost;

public String getOwnerName() {

return ownerName;

}
public void setOwnerName(String ownerName) {

this.ownerName = ownerName;

public int getScreen() {

return screen;

public void setScreen(int screen) {

this.screen = screen;

public void display() {

System.out.println("Stall Name: "+stallName);

System.out.println("Cost: Rs."+cost);

System.out.println("Owner Name: "+ownerName);

System.out.println("Number of Screens: "+screen);

}
}

GOLD STALL.JAVA

public class GoldStall implements Stall{

private String stallName;

private int cost;

private String ownerName;

private int tvSet;


public GoldStall(String stallName, int cost, String ownerName, int tvSet) {

this.stallName = stallName;

this.cost = cost;

this.ownerName = ownerName;

this.tvSet = tvSet;

public void display() {

System.out.println("Stall Name: "+stallName);

System.out.println("Cost: Rs."+cost);

System.out.println("Owner Name: "+ownerName);

System.out.println("Number of TV sets: "+tvSet);

}
}

STALL.JAVA

public interface Stall {

void display();
}//create interface

PREMIUM STALL.JAVA

public class PremiumStall implements Stall{

private String stallName, ownerName;

private int cost, projector;

public PremiumStall(String stallName, int cost, String ownerName, int projector) {

this.stallName = stallName;
this.ownerName = ownerName;

this.cost = cost;

this.projector = projector;

public void display() {

System.out.println("Stall Name: "+stallName);

System.out.println("Cost: Rs."+cost);

System.out.println("Owner Name: "+ownerName);

System.out.println("Number of Projectors: "+projector);

}
}

Round up - Interfaces
 
Write a program to display different types of notifications for the type of bank chosen by implementing
the interface.
 
Create an interface named Notification with the following abstract methods
 notificationBySms( )
 notificationByEmail( )
 notificationByCourier( )
 

Consider a class named ICICI which implements Notification interface


 

Implement the abstract methods in the class ICICI


Method name Description
public void notificationBySms() This method is used to display the message "ICICI - Notification By SMS"
public void notificationByEmail() This method is used to display the message "ICICI - Notification By Mail"
public void notificationByCourier() This method is used to display the message "ICICI - Notification By Courier"
 

Consider a class named HDFC which implements Notification interface


 
Implement the abstract methods in the class HDFC
Method name Description
public void notificationBySms() This method is used to display the message "HDFC - Notification By SMS"
public void notificationByEmail() This method is used to display the message "HDFC - Notification By Mail"
public void notificationByCourier() This method is used to display the message "HDFC - Notification By Courier"

Consider a class BankFactory with two methods


Method Description
public Icici getIcici( ) This method is used to return the object for ICICI class
public Hdfc getHdfc( ) This method is used to return the object for HDFC class

Consider the Main class with main( ) method to test the above class.

The link to download the template code is given below


Code Template

Input and Output format:

The first integer corresponds to select the bank, the next integer corresponds to the type of the
notification.
If there is no valid input then display 'Invalid input'.
 

[Note: All text in bold corresponds to the input and remaining text corresponds to output]

Sample Input and Output 1:

Welcome to Notification Setup


Please select your bank:
1)ICICI
2)HDFC
1
Enter the type of Notification you want to enter
1)SMS
2)Mail
3)Courier
1
ICICI - Notification By SMS

Sample Input and Output 2:

Welcome to Notification Setup


Please select your bank:
1)ICICI
2)HDFC
2
Enter the type of Notification you want to enter
1)SMS
2)Mail
3)Courier
4
Invalid Input

Sample Input and Output 3:

Welcome to Notification Setup


Please select your bank:
1)ICICI
2)HDFC
4
Invalid Input

Problem Requirements:

Java
Keyword Min Count Max Count

interface 1 -

MAIN.JAVA

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {

public static void main(String[] args) throws IOException {

BankFactory bankFactory = new BankFactory();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

ICICI icici;

HDFC hdfc;

System.out.println("Welcome to Notification Setup\nPlease select your bank:\


n1)ICICI\n2)HDFC");

int select = Integer.parseInt(br.readLine());

if(select == 1){

icici = bankFactory.getIcici();

System.out.println("Enter the type of Notification you want to enter\n1)SMS\


n2)Mail\n3)Courier");

int notificationChoice = Integer.parseInt(br.readLine());

if(notificationChoice == 1){

icici.notificationBySms();

} else if (notificationChoice == 2){


icici.notificationByEmail();

}else if(notificationChoice == 3) {

icici.notificationByCourier();

} else {

System.out.println("Invalid Input");

} else if(select ==2) {

hdfc = bankFactory.getHdfc();

System.out.println("Enter the type of Notification you want to enter\n1)SMS\


n2)Mail\n3)Courier");

int notificationChoice = Integer.parseInt(br.readLine());

if(notificationChoice == 1){

hdfc.notificationBySms();

} else if (notificationChoice == 2){

hdfc.notificationByEmail();

}else if(notificationChoice == 3) {

hdfc.notificationByCourier();

} else {

System.out.println("Invalid Input");

} else {

System.out.println("Invalid Input");

ICICI.JAVA

public class ICICI implements Notification{

public void notificationBySms() {

System.out.println("ICICI - Notification By SMS");

}
public void notificationByEmail() {

System.out.println("ICICI - Notification By Mail");

public void notificationByCourier() {

System.out.println("ICICI - Notification By Courier");

BANK FACTORY.JAVA

public class BankFactory {

public ICICI getIcici(){

return new ICICI();

public HDFC getHdfc(){

return new HDFC();

NOTIFICATION.JAVA

public interface Notification {

public void notificationBySms();

public void notificationByEmail();

public void notificationByCourier();

HDFC.JAVA

public class HDFC implements Notification{

public void notificationBySms() {

System.out.println("HDFC - Notification By SMS");


}

public void notificationByEmail() {

System.out.println("HDFC - Notification By Mail");

public void notificationByCourier() {

System.out.println("HDFC - Notification By Courier");

Static Inner Class


 
Write a program to calculate the area of the rectangle and triangle using the static inner class concept
in java.

[Note: Strictly adhere to the object-oriented specifications given as a part of the problem statement. Use
the same class names, attribute names and method names]

Consider an outer class Shape with the following public static attributes


 
Attributes Datatype
value1 Double
value2 Double
 

Consider a static inner class Rectangle that has the outer class Shape.

Include the following method in the Rectangle class


 
Method Name Description
Here Calculate and return the area of the rectangle by accessing the attribu
public Double computeRectangleArea()
Area of the rectangle = (length * breadth)

Consider a static inner class Triangle that has the outer class Shape.

Include the following method in the Triangle class


 
Method Name Description
Here Calculate and return the area of the triangle by accessing the attributes va
public Double computeTriangleArea()
Area of the triangle = (1/2) * (base * height)
 

Include appropriate getters and setters for the outer class attributes in both the inner classes.

Get the option for the shape to compute the area and get the attribute according to the shape option
and set the values to the Shape class attributes. Calculate the area and print the area.

Consider a driver class Main to test the above classes.

The link to download the template code is given below


Code Template

Input Format:

The first line of the input is an integer corresponds to the shape.


The next line of inputs are Double which corresponds to,
For Rectangle(Option 1) get the length and breadth.
For Triangle(Option 2) get the base and height.

Output Format:

The output consists area of the shape.


Print the double value correct to two decimal places.
Print “Invalid choice”, if the option for the shape is chosen other than the given options.
Refer to sample output for formatting specifications.

[All text in bold corresponds to input and rest corresponds to output]

Sample Input and Output 1:

Enter the shape


1.Rectangle
2.Triangle
1
Enter the length and breadth:
10
25
Area of rectangle is 250.00

Sample Input and Output 2:

Enter the shape


1.Rectangle
2.Triangle
2
Enter the base and height:
15
19
Area of triangle is 142.50

Sample Input and Output 3:

Enter the shape


1.Rectangle
2.Triangle
3
Invalid choice
MAIN.JAVA

import java.util.*;

import java.text.*;

public class Main {

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

DecimalFormat df=new DecimalFormat("0.00");

System.out.println("Enter the shape\n1.Rectangle\n2.Triangle");

int input=sc.nextInt();

double value1,value2;

switch (input)

case 1:

System.out.println("Enter the length and breadth:");

Shape.Rectangle rectangle=new Shape.Rectangle();

rectangle.setValue1(sc.nextDouble());

rectangle.setValue2(sc.nextDouble());

System.out.println("Area of rectangle is "+df.format(rectangle.computeRectangleArea()));

break;

case 2:

System.out.println("Enter the base and height:");

Shape.Triangle triangle=new Shape.Triangle();

triangle.setValue1(sc.nextDouble());

triangle.setValue2(sc.nextDouble());

System.out.println("Area of triangle is "+df.format(triangle.computeTriangleArea()));

break;

default:
System.out.println("Invalid choice");

SHAPE.JAVA

public class Shape {

public static double value1;

public static double value2;

public static class Rectangle{

public void setValue1(double nextDouble){

value1=nextDouble;

public static double getValue1(){

return value1;

public void setValue2(double nextDouble){

value2=nextDouble;

public static double getValue2(){

return value2;

public double computeRectangleArea(){

double ar = getValue1()*getValue2();

return ar;
}

public static class Triangle{

public void setValue1(double nextDouble){

value1=nextDouble;

public static double getValue1(){

return value1;

public void setValue2(double nextDouble){

value2=nextDouble;

public static double getValue2(){

return value2;

public double computeTriangleArea(){

double ar = 0.5*(getValue1()*getValue2());

return ar;

}
Exception Introduction
 
  An exception is an unwanted or unexpected event, which occurs during the execution of a program
i.e at run time, that disrupts the normal flow of the program. There are many types of exception which
can occur due to various reasons. Let's know about each of them in this module.
 In this exercise, we'll experiment with Input Mismatch Exception. As the name suggests, when the
input is not compatible with the assigned variable, then Input mismatch exception occurs. Using try
and catch blocks we'll handle the exception.
 
Create a driver class called Main. In the main method, obtain integer input from the user. If the user
enters a different datatype, prompt the user (Refer I/O) else print the obtained value.
[All text in bold corresponds to the input and rest corresponds to the output]
Sample Input and Output 1:

Enter an integer input


5
Entered value is 5

Sample Input and Output 2:

Enter an integer input


5.0
java.util.InputMismatchException

MAIN.JAVA

import java.util.Scanner;

import java.util.InputMismatchException;

public class Main {

public static void main(String[] args){

try{

Scanner sc=new Scanner(System.in);

System.out.println("Enter an integer input");

int n=sc.nextInt();

// if(n==(int) n)

System.out.println("Entered value is "+n);

catch(InputMismatchException g){

System.out.println(g);

}
}
Arithmetic Exception
   
An exception is an unwanted or unexpected event, which occurs during the execution of a program i.e
at runtime, it disrupts the normal flow of the program. For example, there are 10 statements in your
program and there occurs an exception at statement 5, the rest of the code will not be executed i.e.
statement 6 to 10 will not run. If we perform exception handling, the rest of the statement will be
executed. That is why we use exception handling.
 
Write a program to obtain the cost for 'n' days of an item and n as input and calculate the cost per day
for the item. In case, zero is given as input for n, an arithmetic exception is thrown, handle the
exception and prompt the user accordingly.
 
Consider a driver class called Main. In the main method, obtain input from the user and store the
values in integer type. Handle exception if one occurs.
 
The link to download the template code is given below
Code Template

Input format:
The first line of input is an integer which corresponds to the cost of the item for n days.
The second line of input is an integer which corresponds to the value n.

Output format:
If the value of n is zero throws an exception.
Otherwise, print the integer output which corresponds to the cost per day of the item.
 
[All text in bold corresponds to the input and rest corresponds to the output]

Sample Input  and Output 1:

Enter the cost of the item for n days


100
Enter the value of n
 0
java.lang.ArithmeticException: / by zero

Sample Input and Output 2:

Enter the cost of the item for n days


100
Enter the value of n
20
Cost per day of the item is 5
 

Problem Requirements:

Java
Keyword Min Count Max Count

try 1 -

Keyword Min Count Max Count

ArithmeticException 1 -
Keyword Min Count Max Count

catch 1 -

MAIN.JAVA

import java.util.*;

public class Main {

public static void main(String[] args) {

try{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the cost of the item for n days");

int a=sc.nextInt();

System.out.println("Enter the value of n");

int n=sc.nextInt();

int b=a/n;

System.out.println("Cost per day of the item is "+b);

catch(ArithmeticException e){

System.out.println(e);

ArrayIndexOutOfBoundsException

ArrayIndexOutOfBoundsException occurs when the program tries to access the array beyond its
size. 

Write a program to manipulate array operation by handling ArrayIndexOutOfBoundsException

Create an array of size 100 and assume it as seat array. Get the tickets to be booked from  the
user and handle any exception that occurs in Main Class. At last display all the tickets booked.
 
The link to download the template code is given below
Code Template

Input and Output format:


The first line of input consists of an integer which corresponds to the number of seats to be booked.
The next n lines of input consist of the integer which corresponds to the seat number. The seat
number starts from 1 to 100.
If the exception is thrown, then display the exception with the index number. Else display all the
tickets booked
Refer to sample Input and Output for formatting specifications.

[All Texts in bold corresponds to the input and rest are output]

Sample Input and Output 1:

Enter the number of seats to be booked:


5
Enter the seat number 1
23
Enter the seat number 2
42
Enter the seat number 3
65
Enter the seat number 4
81
Enter the seat number 5
100
The seats booked are:
23
42
65
81
100

Sample Input and Output 2:

Enter the number of seats to be booked:


4
Enter the seat number 1
12
Enter the seat number 2
101
java.lang.ArrayIndexOutOfBoundsException: 100
 

Problem Requirements:

Java
Keyword Min Count Max Count

ArrayIndexOutOfBoundsException 1 -

Keyword Min Count Max Count

catch - -

Keyword Min Count Max Count

try 1 -

MAIN.JAVA

import java.util.*;

public class Main {


public static void main(String [] args){

Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of seats to be booked:");

int seats = sc.nextInt();

int [] s = new int[100];

try{

for(int i=1 ; i<=seats ; i++)

System.out.println("Enter the seat number "+ i );

int k = sc.nextInt();

s[k-1] = 1;

System.out.println("The seats booked are:");

for(int i = 0 ; i<100 ; i++)

if(s[i]==1)

System.out.println(1+i);

catch(ArrayIndexOutOfBoundsException ade)

System.out.println(ade);

Parse Exception
 Write a program to implement ParseException for the given date inputs.

Consider a driver class called Main. In the main method, obtain start time and end time for stage event
show, if an exception occurs, handle the exception and notify the user about the right format.
 

The link to download the template code is given below


Code Template

Input format:

The input consists of the start date and end date. 


The format for the date is dd-MM-yyyy-HH:mm:ss

Output format:

Refer sample Input and Output for formatting specifications 

[All text in bold corresponds to the input and rest corresponds to the output]

Sample Input and Output 1:

Enter the stage event start date and end date


27-01-2017-12
Input dates should be in the format 'dd-MM-yyyy-HH:mm:ss'

Sample Input and Output 2:

Enter the stage event start date and end date


27-01-2017-12:0:0
28-01-2017-12:0:0
Start date:27-01-2017-12:00:00
End date:28-01-2017-12:00:00
 

Problem Requirements:

Java
Keyword Min Count Max Count

try 1 -

Keyword Min Count Max Count

catch 1 -

Keyword Min Count Max Count

ParseException 1 -

MAIN.JAVA

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Scanner;

import java.util.Date;

public class Main {

static String startd;

static String endd;

public static void main(String[] args) {

SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy-HH:mm:ss");

Scanner sc=new Scanner(System.in);

System.out.println("Enter the stage event start date and end date");

startd= sc.next();

try {

Date date = formatter.parse(startd);

endd=sc.next();

try{

Date date1 = formatter.parse(endd);

System.out.println("Start date:"+formatter.format(date));

System.out.println("End date:"+formatter.format(date1));

}catch (ParseException e) {

System.out.println("Input dates should be in the format 'dd-MM-yyyy-HH:mm:ss'");

}catch (Exception a){

System.out.println("Input dates should be in the format 'dd-MM-yyyy-HH:mm:ss'");

}
SeatNotAvailableException

An organization is organizing a charity fate for the well being of poor kids. Since the manager was
running short on time, he asked you to help him with the ticket bookings. You being from a
programming background decide to design a program that asks the user about the seat number they
want. Seat booking details are stored in an array. If the seat number requested is available booking
should be done else print the message " SeatNotAvailableException". If the seat number requested is
not in the range throws an exception ArrayIndexOutOfBoundsException.
 

Write a program to throw a custom exception based on the inputs and constraints given.

Create a class SeatNotAvailableException that extends Exception.

In the Main class, create an array of size n*n (n rows each with n seats) which is got from the user.
Get the tickets to be booked from the user and handle any exception that occurs in Main Class. (Take
seat numbers from 0 to (n*n)-1)

Note:
 Vacant seats are denoted by (0) and booked seats are denoted by (1).
 Show message as "Already Booked" as a Custom exception.
 

The link to download the template code is given below


Code Template

Input and Output format:

Refer sample Input and Output for formatting specifications.t of the output.

[All Texts in bold corresponds to the input and rest are output]

Sample Input and Output 1:

Enter the number of rows and columns of the show:


3
Enter the number of seats to be booked:
2
Enter the seat number 1
8
Enter the seat number 2
0
The seats booked are:
1 0 0
0 0 0
0 0 1

Sample Input and Output 2:

Enter the number of rows and columns of the show:


3
Enter the number of seats to be booked:
2
Enter the seat number 1
9
java.lang.ArrayIndexOutOfBoundsException: 9
The seats booked are:
0 0 0
0 0 0
0 0 0

Sample Input and Output 3:

Enter the number of rows and columns of the show:


4
Enter the number of seats to be booked:
3
Enter the seat number 1
15
Enter the seat number 2
14
Enter the seat number 3
15
SeatNotAvailableException: Already Booked
The seats booked are:
0 0 0 0
0 0 0 0
0 0 0 0
0011
MAIN.JAVA

import java.util.*;

public class Main

public static void main(String [] args)throws SeatNotAvailableException

Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of rows and columns of the show:");

int rnc = sc.nextInt();

System.out.println("Enter the number of seats to be booked:");

int booking = sc.nextInt();

int arr[][] = new int[rnc][rnc];

int l;

int arr1d[] = new int[rnc*rnc];

for(int i=1 ; i<=booking ; i++)

System.out.println("Enter the seat number "+i);

l=sc.nextInt();
try{

if(arr1d[l]==1)

throw new SeatNotAvailableException("Already Booked");

arr1d[l] = 1;

catch(ArrayIndexOutOfBoundsException ae)

System.out.println(ae);

break;

catch(SeatNotAvailableException e)

System.out.println(e);

break;

System.out.println("The seats booked are:");

int k=0;

for(int i=0 ; i<rnc ; i++)

for(int j=0; j<rnc ; j++)

arr[i][j]=arr1d[k];

k++;

for(int i=0 ; i<rnc ; i++)

for(int j=0; j<rnc ; j++)


{

System.out.print(arr[i][j]+" ");

System.out.println();

SEAT NOT AVAIABLE EXCEPTION.JAVA

import java.util.*;

public class SeatNotAvailableException extends Exception

SeatNotAvailableException(String s)

super(s);

Algorithmic Strategies - Pseudocode and Flowchart exercises / Practice / Mandatory

Write an algorithm to find the factorial of given number.


Factorial of a Number:
Read Number; Set Fact=1, i=1
WHILE i<=number
Fact=Fact*i
i=i+1
END-WHILE
WRITE Fact

Write an algorithm to generate the Fibonacci Sequence upto to the given number.
Fibonacci Series:
Read number,Set variables j=0,k=1, l=1
FOR: (integer count is less than number, INCREMENT count every loop) DO
PRINT integer j
SET j=k, k=l, l=j+k
END FOR:

Reverse of a number
 

Write a program to reverse the digits of a number.

(Note : Please use initialize statement before input statement)


 

Input format :
Input consists of an integer value.

Output format :
Output consists of the reverse of the given number.

[ Refer Sample Input and Output for further details ]

Sample Input and Output 1 :


[ All text of bold corresponds to Input and the rest output]
Enter the number :
5642
Reverse of the number is 2465
 

Sample Input and Output 1 :


Enter the number :
144
Reverse of the number is 441
 

startinitializerev=0,rem=0read nisn!=0rem=n%10rev=rev*10+remn=n/10print revendyesno


REVIEW ANSWER NEXT

SWAPPING OF TWO ROLL NUMBERS


Rita was about to award 2 students with 1st and 2nd prize. But unfortunately, he interchanged both of
them. Consider the first number as the roll number of the student who won a the1st prize and the next
roll number of the student who won 2nd prize. Can you write a program to swap two numbers without
using a third variable?
 Input format  :
  Input consists of two integers.
 Output format :
  Output consists of two integers which are swapped.
Sample Input and Output :
[ All text of bold corresponds to input ]
Enter values:
15
2
Values after swapping:
2
15

starta=a+bb=a-ba=a-bendinput a,bprint a,b

ELIGIBLE OR NOT?
 
           Pactrick and Johnny found that they have to clear new criteria to play the game. The eligibility
criteria for playing the game is that the participant should be above 10 years and his/ her height
should be above 140cm. (Both 10 and 140 are inclusive). If a participant is eligible he / she will be
allowed inside. Both Patrick and Johnny wanted to know whether they are eligible to play. Write a 
program to find whether a participant is eligible or not.

Input Format:

Input consists of two integers which corresponds to age and height of a person (in cms) respectively.

Output Format :

Display whether the person is eligible or not.

Sample input and output 1:

[All text in bold corresponds to input and the rest corresponds to output]

Enter your Age :


19
Enter your Height :
150
Eligible to play

Sample input and output 2:

Enter your Age :


17
Enter your Height :
130
Not Eligible to play
REVIEW ANSWER NEXT
startPrint 'Enter your age :'Input agePrint 'Enter your height :'Input heightIs age > 10 and height > 140 ?Print ' Eligible to play'yesPrint
'Not Eligible to play'noend
REVIEW ANSWER NEXT

You might also like