0% found this document useful (0 votes)
8 views

Database Practical Questions

This project report titled 'Practical File' is submitted by Miss Srushti Mukund Bajaj as part of the I.T practical work for the Sr. Sec. CBSE level during the academic year 2024-2025. It includes various exercises related to database practicals, SQL queries, and project acknowledgments, showcasing the candidate's original work and understanding of the subject. The report is guided by Mrs. Reshma Shinde and certified by the school authorities.

Uploaded by

reshma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Database Practical Questions

This project report titled 'Practical File' is submitted by Miss Srushti Mukund Bajaj as part of the I.T practical work for the Sr. Sec. CBSE level during the academic year 2024-2025. It includes various exercises related to database practicals, SQL queries, and project acknowledgments, showcasing the candidate's original work and understanding of the subject. The report is guided by Mrs. Reshma Shinde and certified by the school authorities.

Uploaded by

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

PROJECT REPORT

On

“Practical file”

As a part of Sr.Sec.Level,CBSE
I.T Practical

Submitted by
Miss. Srushti Mukund Bajaj
Roll No
(………………..)
Under the guidance of
Mrs.Reshma Shinde

Through
Sinhgad Public School,Korti,Pandharpur
Year
(2024-2025)

Page
1
Certificate

This is to certify that the project work titled


“Practical file” is bonafied record done by Miss.
Srushti Mukund Bajaj of Class: XII
DIV.:A Board Roll No.:____________ as a part of
Practical work for I.T. during the year 2024-2025.

Mrs.Reshma Shinde
Mrs.Smita Navale
Departement of I.T.
Principal

Certified that the candidate was examined by us in


the project work/ viva voice examination held at
Sinhgad Public School,Korti,Pandharpur on
…………………. .

Page
2
Internal Examiner
External Examiner

Date :- ______________

Page
3
Acknowledgement

I would like to express my sincere gratitude to


the Principal Mrs. Smita Navale and Head
Mistress Mrs.Smitha Nair for encouraging
us an giving support time to time.

I would like to express my sincere gratitude


to my Information Technology Teacher
Mrs.Reshma Shinde, Department of
Information Technology for their vital
support, guidance and encouragement
without which this project would not have
come forth .

I wish special thanks to my parents for their


undivided support and interest who inspired
me and encouraged me to go my own way,

Page
4
without which I would be unable to complete
my project.

Page
5
Declaration

Respected madam,
I undersigned hereby declare that, the
project entitled
‘Practical file’ , with special reference to
under the guidance of
to Sinhgad Public School, Korti, Pandharpur
for the part of information technology Project
work, at Sr.Sec.CBSE Level, written and
submitted by me is an original work.

The empirical findings in the report are based


on data collected by me preparing project
report. I’ve not copied from any report.

Name : Miss. Srushti Mukund Bajaj

Place : Korti, Pandharpur

Page
6
Date : …………………….

Page
7
Database Practical
Questions
Exercise 1
Q.1] Create table Sales_people with fields snum, sname,
city, commission.
Answer:-
Code & output:

Q.2]Create table orders with fields onum, odate ,snum,


amt.
Answer:-
Code & output:

Q.3]Create table customers with fields cnum, cname, city,


rating, snum.
Answer:-

Page
8
Code & output:

Q.4] Add at least 10 records in Sales_people, orders,


customers1.
Answer:-
Code & output:

Page
9
Q.5] Display details of all tables sales_people, orders,
customers1.
Answer:-
Code & output:

Page
10
Q.6] Display all details of fields sname,commission.
Answer:-
Code & output:

Q.7] Display the odate, snum,onum,amt from orders


table.
Answer:-
Code & output:

Page
11
Q.8] Display snum of sales_people with the distinct snum.
Answer:-
Code & output:

Q.9] Display name & city of salesman where city is


“Pune”.
Answer:-
Code & output:

Q.10] Display all details of customer where rating is 100.


Answer:-
Code & output:

Q.11] Display all details from customer table where


salespersons number is 7.
Answer:-
Code & output:

Page
12
Q.12] Display the numbers of sales persons, with orders
currently in the orders table without any repeats.
Answer:-
Code & output:

Q.13] Display all customers where rating more than 200.


Answer:-
Code & output:

Q.14] Display all customers where city is ‘Mumbai’ rating


is more than 100.
Answer:-
Code & output:

Q.15] Display all customers where city is either ‘Pune’ or


‘Mumbai’.
Answer:-
Code & output:

Page
13
Exercise 2

Q.1] List all customers not having city ‘Pune’ or rating


greater than 100.
Answer:-
Code & output:

Q.2] List all orders between order dates 10/03/05 to


30/03/05.
Answer:-
Code & output:

Q.3] Display all orders more than 1000 amt.


Answer:-
Code & output:

Page
14
Q.4] Display names & cities of all salespeople in ‘Pune’
with a commission above 100.
Answer:-
Code & output:

Q.5] Display all customers excluding those, with rating


less than equal to 100, unless they are located in
‘Nashik’.
Answer:-
Code & output:

Q.6] Display all sales persons names starting with


character ‘G’. The 4th character is ‘a’ & the rest of
characters will be any.
Answer:-
Code & output:

Q.7] Find all records from customers table where city is


not known i.e. NULL.
Answer:-

Page
15
Code & output:

Q.8] Display all customer’s names begins with a letter A


to G.
Answer:-
Code & output:

Q.9] Assume each salesperson has a 12% commission on


order amt.Display onum,snum,commission for that order.
Answer:-
Code & output:

Q.10] Display all customers records,arranged on name.


Answer:-
Code & output:

Page
16
Q.11] Display all customers records arranged on rating in
desc Order.
Answer:-
Code & output:

Q.12] Display all sales persons records arranged on


snum.
Answer:-
Code & output:

Q.13] Display the count for total number of customers in


customers table.

Page
17
Answer:-
Code & output:

Q.14] Display the count of snum in order table without


any duplication of snum.
Answer:-
Code & output:

Q.15] Display the counts of all orders for Feb 05.


Answer:-
Code & output:

Exercise 3
Q.1] Display the count of different non-NULL city values in
the customer’s table.
Answer:-
Code & output:

Page
18
Q.2] Display the maximum outstanding amount as
blnc+amt.
Answer:-
Code & output:

Q.3] Display the minimum rating within customers table.


Answer:-
Code & output:

Q.4] Display average of amount.


Answer:-
Code & output:

Page
19
Q.5] Display sales persons number wise maximum amt
from orders table.
Answer:-
Code & output:

Q.6] Display the largest order taken by each salesperson


on each table.
Answer:-
Code & output:

Q.7] Display the details of maximum orders above 3000.


Answer:-
Code & output:

Q.8] Display details of orders number & date wise.


Answer:-
Code & output:

Page
20
Q.9] Display customer’s highest ratings in each city.
Answer:-
Code & output:

Q.10] Write a query that totals the orders for each day &
places the Results in descending order.
Answer:-
Code & output:

Q.11] Add a column curr_bal in orders table for current


balance.
Answer:-
Code & output:

Page
21
Q.12] Increment wise commission of all sales persons by
200.
Answer:-
Code & output:

Q.13] Delete all orders where odate is less than 5-2-05.


Answer:-
Code & output:

Q.14] Display names of all customers matched with the


salespeople Serving them.
Answer:-
Code & output:

Page
22
Q.15] Display the names & cities of all customers with
same rating as ‘Anjali’.
Answer:-
Code & output:

Exercise 4

Q.1] Write a query that selects the total amt in orders for
each Salesperson for whom this total is greater than the
amount of The largest order in table.
Answer:-
Code & output:

Q.2]Find the maximum value of amount from orders.


Answer:-
Code & output:

Page
23
Q.3] Create a union of two queries that shoes the
names,cities & rating Of all customres. Those with a
ratings of 200 or greater will also have ratings “High
rating”, while the orders will have the words “Low rating”.
Answer:-
Code & output:

Q.4] Create an index that would permit each salesperson


to retrieve his or her orders grouped by date quickly.
Answer:-
Code & output:

Q.5] Create a view that shows all the customers who


have highest ratings.
Answer:-
Code & output:

Page
24
Q.6] Create a view that shows number of salespeople in
each city.
Answer:-
Code & output:

Q.7] Display names of all customers matched with the


salespeople Serving them.
Answer:-
Code & output:

Page
25
Q.8] Find all orders by customers not located in same
cities as their Salespersons.
Answer:-
Code & output:

Q.9] Display each order number followed by the name of


customer Who made it.
Answer:-
Code & output:

Q.10] Calculate the amount of salespersons commissions


on each order by a customer with a rating above 100.
Answer:-
Code & output:

Page
26
Q.11] Display the pairs of salespeople who are living in
the same city.Exclude combinations of sales people with
themselves as well as duplicate rows with the order
reversed.
Answer:-
Code & output:

Q.12] Write a query that uses a sub-query to obtain all


orders for the customer named ‘Parth’. Assume you do
not know the customers number.
Answer:-
Code & output:

Q.13] Write a query that produces the names & ratings


of all customers who have above-average orders.
Answer:-
Code & output:

Page
27
Q.14] Write a command that produces the name &
number of each salesperson & each customer with more
than one current order. Put results in Alphabetic order.
Answer:-
Code & output:

Q.15] Consider the following schema definitions:

Branch (branchNo, street, city, postcode)

Staff (staffNo, fName,lName, position, gender, DOB, salary,


branchNo)

PropertyforRent (propertyNo, street, city, postcode, type, rooms, rent,


ownerNo,

staffNo, branchNo)

Page
28
Client (clientNo, fName, lName, telNo, prefType, maxRent)

PrivateOwner (ownerNo, fName, lName, address, telNo)

Viewing (clientNo, propertyNo, viewDate, comment)

Registration (clientNo, branchNo, staffNo, dateJoined)

Answer:-
Codes & outputs:

Page
29
Exercise 5
Q.1] Create a database in MYSQL with suitable name,
open database.
Answer:-

Page
30
Code & output:

Q.2] Create a SQL query/command to open database.


Answer:
Code & output:

Q.3] Write a query to view the current database.


Answer:-
Code & output:

Q.4] Create following tables with given columns:


student(Rollno,Name,Date_of_Birth).
Answer:-
Code & output:

Page
31
Q.5] Write a query to view the structure of table.
Answer:-
Code & output:

Q.6] Create following table:


Employee(employee_id, emp name,
date_of_birth,gender,date_of_joining,salary)
Create primary key for employee_id. Insert records in
above table.
Answer:-
Code & output:

Q.7] Create table fee with following fields.


(Rollno,date_of_fees.rcpt_no,amount).
Insert records in above table.

Page
32
Answer:-
Code& output:

Q.8] Apply the NOT NULL constraint while creating table.


Answer:-
Code & output:

Q.9] Apply unique constraint on table field.


Answer:-
Code & output:

Page
33
Q.10] Create a query for applying check constraint.
Answer:-
Code & output:

Q.11] How to modify the structure of table.


Alter a table with requirements given below:
Add a column, remove a column, modify a column
datatype, modify name and size of column, add a
constraint, remove constraint.
Answer:-
Code & output:

Page
34
Page
35
Q.12] Alter table commands. Create a command to
remove NOT NULL.
Answer:-
Code & output:

Q.13] Delete a structure of table by using suitable


command
Answer:-
Code & output:

Q.14] Add records in table with insert command.

Page
36
Answer:-
Code & output:

Q.15] How to view records added in table give suitable


query to view table data as per below:
I. Select all records from table.
II. To see only single column.
III. To see any 3 fields from table.
Answer:-
Code & output:
i.

Page
37
ii.

iii.

Q.16] Display unique cities from student table.


Answer:-
Code & output:

Exercise 6
Q.1] How to display details from table with all keyword.

Page
38
Answer:-
Code & output:

Q.2] Select data from table based on condition:


Display details from table fees whose amount is more
than 5000.
Answer:-
Code & output:

Q.3] Use of operators in select command:


I. Write a query to display rollno and 5%discount of fee
amount from the fees table.
II. Show the details of those whose city is “Kota”
III. Display records from student table whose dob is after
31-12-2001.
Answer:-
Code & output:

Page
39
I.

II.

III.

Q.4] Check if any record added is null? Give suitable


query to find null value from table.
Answer:-
Code & output:

Q.5] In operator. Find a record from table which match to


given values or set of values.

Page
40
Answer:-
Code & output:

Q.6] Display names of students where name starts with


‘A’.
Answer:-
Code & output:

Q.7] Sorting data from table using order by clause:


Show details from table sorted in order to name.
Answer:-
Code & output:

Page
41
Q.8] Create a query to display name of employee and his
date of birth name the output fields with alias ‘Name of
Employee’ and ‘Date of Birth’ respectively.
Answer:-
Code & output:

Q.9] How to insert a text in a query give example and


output.
Answer:-
Code & output:

Q.10]Make use of Aggregate functions:


MIN,MAX,AVG,SUM,COUNT.

Page
42
Answer:-
Code & output:

Q.11]Create a query to display deptid count for all record


group by deptid.
Answer:-
Code & output:

Q.12] Having clause why to be used with group by clause


give suitable query.
Answer:-

Page
43
Code & output:

Q.13] Delete record from employee table whose empid is


404.
Answer:-
Code & output:

Q.14] Combine data of two tables.


Answer:-
Code & output:

Page
44
Q.15] Refer table employee and dept create foreign key
on employee table on referential action, on delete set
null, on update cascade.
Answer:-
Code & output:

Q.16]Drop foreign key from the employee table.


Answer:-
Code & output:

Page
45
Page
46
Java NetBeans Practical
Questions
Q.1] Design a Java Application using java class to wish
good morning to everyone

Answer:-
Code:
 public static void main(String[] args){
System.out.print("Good morning");
}
Output:

Q.2] Accept 5 products name and price with their


quantity, display gross total for products purchased.
Answer :-
Code:
 import java.util.Scanner;
public class GrossTotalCalculator {
public static void main(String args[])
{

Page
47
Scanner scanner=new Scanner(System.in);
String[] productName=new String[5];
double[] price=new double[5];
int[] quantity=new int[5];
double grossTotal=0;

for(int i=0;i<5;i++)
{
System.out.println("Enter Product" + (i+1) +
"details : ");
System.out.print("Name :");
productName[i]=scanner.nextLine();
System.out.print("Price :");
price[i]=scanner.nextDouble();
System.out.print("Quantity :");
quantity[i]=scanner.nextInt();
scanner.nextLine();

double subtotal=price[i]*quantity[i];
grossTotal += subtotal;
System.out.println();

Page
48
//display product list and grossTotal
System.out.println("Product List :");
for(int a=0;i<5;i++)
{
System.out.print((i+1)+"."+productName[i]+"-
Price :"+price[i]+"-Quantity :"+quantity[i]);
}
System.out.println("Gross Total :" +grossTotal);
}}}
Output :

Q.3] Write a program to accept marks and give result


based on the following information condition:
If marks are more than
90=A1,80=A2,70=B1,60=B2,50=C1,40=C2,else fail.
Answer:-
Code :
 import java.util.Scanner;
public class GradeCalculator {
public static void main(String args[])

Page
49
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter Student Name :");
String name=scanner.nextLine();
System.out.println("Enter marks(out of 100):");
int marks=scanner.nextInt();
String grade=calculateGrade(marks);
System.out.println("\nResult:");
System.out.println("\nName:"+name);
System.out.println("\nMarks:"+ marks);
System.out.println("\nGrade:"+grade);
scanner.close();

}
public static String calculateGrade(int marks)
{
if(marks>=90)
{
return"A1";
}
else if(marks>=80)

Page
50
{
return"A2";
}
else if(marks>=70)
{
return"B1";
}
else if(marks>=60)
{
return"B2";
}
else if(marks>=50)
{
return"C1";
}
else if(marks>=40)
{
return"C2";
}
else {
return"fail";

Page
51
}}}
Output :

Q.4] Write a program displaying whether a given letter is


vowel or consonant, use switch case.
Answer:-
Code:
 import java.util.Scanner;
public class VowelorConsonant {
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter a Letter :");
char letter=scanner.next().charAt(0);
letter=Character.toLowerCase(letter);
switch(letter)
{
case 'a':
case 'e':

Page
52
case 'i':
case 'o':
case 'u':
System.out.println(letter+"is a vowel");
break;
default:
if(letter>='a'&&letter<='z')
{
System.out.println(letter+"is a consonant");
}
else{
System.out.println("Invaild input.Please enter
a letter");
} }
scanner.close();
}}
Output :

Q.5] Write a program to find a factorial of given number.

Page
53
Answer:-
Code :
 import java.util.Scanner;
public class FactorialCalculator {
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter a number:");
int number=scanner.nextInt();
long factorial=calculateFactorial(number);
if(factorial!=1){
System.out.println("Factorial
of:"+number+"="+factorial);
}
else{
System.out.println("Factorial is not defined for
negative numbers");
}
scanner.close();
}

Page
54
public static long calculateFactorial(int number)
{
if(number<0){
return -1;
}
else if(number==10 || number==1){
return 1;
}
else{
long factorial=1;
for(int i=2;i<=number;i++){
factorial=1;
}
return factorial;
}}}
Output :

Q.6] Create a class to calculate total marks of 5 subjects


and display percentage.

Page
55
Answer:-
Code :
 import java.util.Scanner;
public class MarksCalculator {
private String[] subjectNames=new String[5];
private int[] marks=new int[5];
private int totalMarks;
private double percentage;

public void inputMarks()


{
Scanner scanner=new Scanner(System.in);
for(int i=0;i<5;i++)
{
System.out.println("Enter subject :" +(i+1)+
"Name:");
subjectNames[i]=scanner.nextLine();
System.out.println("Enter" +subjectNames[i] +"
Marks(out of 100):");
marks[i]=scanner.nextInt();
scanner.nextLine();

Page
56
}
scanner.close();
}
public void calculateTotalMarks(){
totalMarks=0;
for(int mark:marks){
totalMarks+=mark;
}
}
public void calculatePercentage(){
percentage=(double)totalMarks/5;
}
public void displayResult(){
System.out.println("\nResult:");
for(int i=0;i<5;i++){
System.out.println(subjectNames[i] +" : "
+marks[i]);
}
System.out.println("Total Marks:"+ totalMarks);
System.out.printf("Percentage:%.2f%%
%n",percentage);

Page
57
}
public static void main(String args[]){
MarksCalculator calculator=new MarksCalculator();
calculator.inputMarks();
calculator.calculateTotalMarks();
calculator.calculatePercentage();
calculator.displayResult();
}
}
Output :

Q.7] Create class which will use String Functions for


following reasons:
Convert given String in upper and lowercase.
To check whether string starts with specified
character.

Page
58
To get the length of specified string.
Answer:-
Code :
 public class StringOperations {
private String inputString;

public void setInputString(String inputString){


this.inputString=inputString;
}

//1.Covert string to uppercase and lowercase


public void convertCase(){
System.out.println("Original String:"+inputString);

System.out.println("Uppercase:"+inputString.toUppe
rCase());

System.out.println("Lowercase:"+inputString.toLowe
rCase());
}

//2.check if string starts with specifeied character


public void checkStartsWith(char c){
System.out.println("Does string start
with:"+c+'?'+inputString.startsWith(String.valueOf(c
)));
}

//3.get length of specified string


public void getStringLength(){

Page
59
System.out.println("Length of
String:"+inputString.length());
}

public static void main(String args[]){


StringOperations operations=new
StringOperations();
operations.setInputString("Hello World");
operations.convertCase();
operations.checkStartsWith('H');
operations.checkStartsWith('J');
operations.getStringLength();
}
}
Output :

Q.8] Write a program to demonstrate the working of


thread and runnable interface in java.
Answer:-
Code :
 public class threadsDemo extends Thread{

Page
60
public void run(){
System.out.println("My thread is in running
state.");
}
public static void main(String args[]){
threadsDemo obj=new threadsDemo();
threadsDemo obj1=new threadsDemo();
obj.start();
obj1.start();
}
}
 public class MultiThreadingDemo {
public void run(){
for(int i=0;i<=5;i++){
System.out.println("My Thread is in running
state."+ i);
}
}
public static void main(String args[])
{
MultiThreadingDemo obj=new
MultiThreadingDemo();
Thread tobj=new Thread((Runnable) obj);
tobj.start();
}
}
Output:

Page
61
Q.9] Write a program to accept 10 students marks by
using arrays, display that marks. Use suitable datatype if
any if marks are below 35 give error message(assertion).
Answer:-
Code :
 import java.util.Scanner;
public class StudentMarks {
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
int[] marks=new int[10];
for(int i=0;i<10;i++){
System.out.print("Enter marks for student "+
(i+1)+":");
marks[i]=scanner.nextInt();
assert marks[i]>=35:"Error:Marks cannot be
below 35";
}
System.out.println("\nStudent Marks:");

Page
62
for(int i=0;i<10;i++){
System.out.println("Student"+(i+1)+":"+marks[i]);
}
scanner.close();
}
}
Output :

Q.10] Write a program to display 1 to 10 numbers with


their index numbers by using array.
Answer:-
Code :
 public class NumberDisplay {
public static void main(String args[])
{

Page
63
int[] numbers={1,2,3,4,5,6,7,8,9,10};
System.out.println("Index\tNumbers");
System.out.println("--------------");
for(int i=0;i<numbers.length;i++)
{
System.out.println(i+"\t"+numbers[i]);
}
}
}
Output :

Q.11] Namita wanted to make class ‘author’ in java which


have default and parameterized constructor. The class
has data member as authorid int, author name string,
book name string, price float. Help her in making the
structure of the class with default and parameterized
constructor.
Answer:-

Page
64
Code :
 public class Author {
public int authorid;
private String authorName;
private String Bookname;
private float price;

public Author()
{
authorid=0;
authorName=" ";
Bookname=" ";
price=0;
}
public Author(int r,String s,String f,float p)
{
authorid=r;
authorName=f;
Bookname=f;
price=p;
}

Page
65
public static void main(String args[])
{
Author a1=new Author(10237,"Aman
Sharma","Mukesh Sharma",100.5f);
a1.display();
}}
Q.12] Create a user defined method to find whether the
number 105 appears in the given Array or not.(The Array
has 100,102,105,118,119,123,130,114,106).
Answer:-
Code:
 public class Main {
public static void main(String args[])
{
int[] array={100,102,105,11,119,123,130,114,106};
int target=105;
boolean result=findNumber(array,target);
System.out.println("Does"+target+"exist in the
array");
}
public static boolean findNumber(int[] array,int target)
{

Page
66
for(int num:array)
{
if(num==target){
return true;
}
}
return false;
}
}
Output :

Q.13] Write a program in java to print the following


series: 1, 2, 4, 7, 11, 16……
Answer:-
Code:
 public class practice1 {
public static void main(String args[])
{
int n=6;
int[] series=new int[n];

Page
67
series[0]=1;
for(int i=1;i<n;i++)
{
series[i]=series[i-1]+i+1;
}
System.out.println("Series: ");
for(int num:series)
{
System.out.print(num+"");
}
}
}
Output:

Q.14] Write a program for reverse the given string.


Answer:-
Code :
 import java.util.Scanner;
import java.lang.String;

Page
68
public class ReverseString {
public static void main(String args[])
{
String str1="Sinhgad" , str2=" ";
char ch;
System.out.println("Original string is :"+str1);
for(int i=0;i<str1.length();i++){
ch=str1.charAt(i);
str2=ch+str2;
System.out.println(str2);
}
}
}
Output :

Q.15] Write the program to show the value of a and b.


Answer:-
Code :

Page
69
 public class extra_program {
public int a;
public int b;
public extra_program(){
a=0;
b=0;
}
static void extra_program(int a,int b){
a=16;
b=78;
}
public static void main(String args[]){
extra_program x=new extra_program();
extra_program a=new extra_program();
extra_program b=new extra_program();
System.out.println("The value of a is"+a);
System.out.println("The value of b is"+b);
}
}
Output :

Page
70
Q.16] Write a program to check do while loop.
Answer:-
Code :
 import java.util.Scanner;
import java.lang.String;
public class doWhileloop {
public static void main(String args[]){
int total=1;
Scanner s=new Scanner(System.in);
System.out.println("Enter the number to find
factorial");
int fact=s.nextInt();
for(int i=1;i<=fact;i++){
total=total*i;
}
System.out.println("Factorial of "+fact+"is "+total);
}
}

Page
71
Output :

Q.17] Create class student where rollno and student


name can be seen.
Answer:-
Code :
 import java.util.Scanner;
import java.lang.String;
public class Student {
int rollno;
String name;
void get(){
Scanner s=new Scanner(System.in);
System.out.println("Enter rollno");
rollno=Integer.parseInt(s.next());
System.out.println("Enter your name ");
name=s.next();
}
void set(){
System.out.println("Enter rollno
"+rollno+"Enter your name"+ name);
}}

Q.18] Show the sum of the numbers.

Page
72
Answer:-
Code :
 import java.util.Scanner;
public class SumOfNumbers {
static int sum(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter first no");
int a=Integer.parseInt(sc.next());
System.out.println("Enter second no");
int b=Integer.parseInt(sc.next());
System.out.println("Enter third no");
int c=Integer.parseInt(sc.next());
int s=a+b+c;
return s;
}
public static void main(String args[]){
int t=sum();
System.out.println("Total is "+t);
}
}
Output :

Q.19] Write a program to check string palindrome or not.


Answer:-

Page
73
Code :
 public class Palinder {
private static boolean is;
public static boolean isPalinder(String str){
String rev=" ";
boolean answer=false;
for(int i=str.length()-1;i>=0;i--){
rev=rev+str.charAt(i);
}
if(str.equals(rev)){
answer=true;
}
return answer;
}
public static void main(String args[]){
String str="racercar";
str=str.toLowerCase();
boolean a;
a=isPalinder(str);
System.out.println(a);
}

Page
74
}
Output :

Q.20] Write a application to compare three numbers as


maximum and minimum.
Answer:-
Code :
 import java.util.Scanner;
public class Max_Min {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first number");
int a=sc.nextInt();
System.out.println("Enter the second number");
int b=sc.nextInt();
System.out.println("Enter the third number");
int c=sc.nextInt();
int max;
if(a>b)
max=a;
else
max=b;
if(max<c)
max=c;

Page
75
System.out.println("Maximum "+max);
int min;
if(a>b)
min=a;
else
min=b;
if(min<c)
min=c;
System.out.println("Minimum "+min);
}
}
Output :

Q.21] Write a program for even number.


Answer:-
Code :
 public class EvenNo {
public static void main(String args[]){
int i;
for(i=0;i<=20;i++){
if(i%2==0)
System.out.println(i+" is even number");

Page
76
else
System.out.println(i+" is odd number");
}
}
}
Output :

Q.22] Give example of conditional program.


Answer:-
Code :
 import java.util.Scanner;
public class Conditional {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter age :");
int age=Integer.parseInt(sc.next());
System.out.println("Enter marks :");
int marks=sc.nextInt();

Page
77
if(age>=18){
if(marks<=70)
System.out.println("Admission allowed");
}
else
System.out.println("Admission not allowed");
}
}
Output :

Q.23] Write a program for assertion with example.


Answer:-
Code :
 import java.util.Scanner;
public class Assertion {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the price");
int price=Integer.parseInt(sc.next());
assert price<=100:("Price is inavlid and above
100");
System.out.println("Price is "+price);
}
}

Page
78
Output :

Q.24] Write a program using constructors.


Answer:-
Code:
 public class constructors {
public int no1;
public int no2;
public constructors(){
no1=0;
no2=0;
}
public constructors(int a,int b){
no1=a;
no2=b;
System.out.println(no1+" "+no2);
}
public static void main(String args[]){
constructors c1=new constructors();
constructors c2=new constructors(6,1);
}

}
Output :

Page
79
Q.25] Design a menu card and write a program.
Answer:-
Code:
 import javax.swing.JOptionPane;
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {

int price=0;
int a,b,c,d,e;
if(jCheckBox1.isSelected())
a=110;
else
a=0;
if(jCheckBox2.isSelected())
b=150;
else
b=0;
if(jCheckBox3.isSelected())
c=160;
else
c=0;
if(jCheckBox4.isSelected())
d=60;
else

Page
80
d=0;
if(jCheckBox5.isSelected())
e=130;
else
e=0;
int total=a+b+c+d+e;
jTextField1.setText(“ ”);
}
 import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {

JOptionPane.showMessageDialog(this,"REcord
updated payment successful");
}
Design & output :-

Q.26] Accept the number from user to calculate square


and cube of numbers.
Answer:-
Code:

Page
81
 import java.util.Scanner;
public class calculate {
public static void main(String args[]){
int num;
System.out.println("Enter an integer number :\
n");
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
System.out.println("Square of "+num+" is
"+Math.pow(num,2));
System.out.println("Cube of "+num+" is
"+Math.pow(num,3));
}
}
Output:

Q.27] Write a program to show the details in textarea.


Answer:-
Code:
 private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {
String fullName=jTextField1.getText();
String address=jTextField2.getText();

Page
82
long
MobileNo=Long.parseLong(jTextField3.getText());
String bloodGroup=jTextField4.getText();
jTextArea1.setText("Full Name :"+fullName+"\n
Address :"+address+"\n Mobile No.:"+MobileNo+"\n
Blood Group"+bloodGroup);
}
 private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {
jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
jTextField4.setText(" ");
}
 private void
jButton3ActionPerformed(java.awt.event.ActionEve
nt evt) {

System.exit(0);
}
Design & output:

Page
83
Q.28]Calculate the temperature of the following cities:
Latur , Solapur ,Mumbai , Pune , Ratnagiri and Lonavala.
Answer:-
Code:
 private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {

String s=(String)CityList.getSelectedItem();
jTextField1.setText(s);
int i=CityList.getSelectedIndex();
switch(i)
{
case 0:jTextField2.setText("15 Degree
Celcius");
break;
case 1:jTextField2.setText("28 Degree
Celcius");
break;
case 2:jTextField2.setText("29 Degree
Celcius");
break;

Page
84
case 3:jTextField2.setText("27 Degree
Celcius");
break;
case 4:jTextField2.setText("31 Degree
Celcius");
break;
case 5:jTextField2.setText("31 Degree
Celcius");
break;
default:jTextField2.setText("0");
}

Design & output:

Q.29] Write a program to calculate area and perimeter of


circle.
Answer:-
Code:
 import javax.swing.JOptionPane;
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {

Page
85
String r=jTextField1.getText();
float radius=Float.parseFloat(r);
float area=3.14f*radius*radius;
JOptionPane.showMessageDialog(this,"Area of
circle is "+area);

 import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {

String r=jTextField1.getText();
float radius=Float.parseFloat(r);
float perimeter=2*3.14f*radius;

JOptionPane.showMessageDialog(this,"Perimeter of
circle is "+perimeter);
}
Design & output:

Q.30] Write a program to calculate area and perimeter of


square.
Answer:-

Page
86
Code:
 import javax.swing.JOptionPane;
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {

String s=jTextField1.getText();
float side=Float.parseFloat(s);
float area=side*side;
JOptionPane.showMessageDialog(this,"Area of
square is "+area);
}
 import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {

String s=jTextField1.getText();
float side=Float.parseFloat(s);
float perimeter=4*side;

JOptionPane.showMessageDialog(this,"Perimeter of
square is "+perimeter);

}
Design & output:

Page
87
Page
88

You might also like