IT PRACTICAL RECORD CLASS – 12 3.
Write a program to demonstrates usage of the switch statement for
finding week day by taking value from user.
1. Write a program to calculate percentage calculator program, using import java.util.Scanner;
three variables named marks_obtained, total_marks and percentage. public class DayOfWeek {
public class calcper { public static void main(String[] args) {
public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
int total_marks = 400; System.out.print("Enter a number (1-7) representing the day of the week: ");
double marks_obtained = 346; int today = scanner.nextInt();
double percentage = 0.0; String day = "";
percentage = (marks_obtained/total_marks)*100; switch (today) {
case 1:
System.out.println("Student 1's Percentage = "+percentage);
day = "Monday";
marks_obtained = 144;
break;
percentage = (marks_obtained/total_marks)*100; case 2:
System.out.println("Student 2's Percentage = "+percentage); day = "Tuesday";
break;
OUTPUT case 3:
Student 1's Percentage = 86.5 day = "Wednesday";
Student 2's Percentage = 36.0 break;
case 4:
2. Write a program to store textual data. day = "Thursday";
public class Main { break;
public static void main(String[] args) { case 5:
Scanner scanner = new Scanner(System.in); day = "Friday";
System.out.print("Enter first name: "); break;
String first_name = scanner.nextLine(); case 6:
System.out.print("Enter middle initial: "); day = "Saturday";
char middle_name = scanner.next().charAt(0); break;
System.out.print("Enter last name: "); case 7:
String last_name = scanner.nextLine(); day = "Sunday";
last_name = scanner.nextLine(); break;
default:
System.out.println(first_name + " " + middle_name + " " + last_name); day = "Incorrect Day!";
break;
scanner.close(); }} }
System.out.println(day)
OUTPUT scanner.close(); }}
Mahendra Kumar Sahu OUTPUT
Enter a number (1-7) representing the day of the week: 5
Friday
1|P a ge
4. WAP in java to add two numbers. }}
import java.util.Scanner; OUTPUT
Enter a number: 5
public class AddTwoNumbers { Factorial: 120
public static void main(String[] args) { 6. Leap Year Check.
Scanner scanner = new Scanner(System.in); import java.util.Scanner;
public class LeapYear {
System.out.print("Enter first number: "); public static void main(String[] args) {
int num1 = scanner.nextInt(); Scanner scanner = new Scanner(System.in);
System.out.print("Enter a year: ");
System.out.print("Enter second number: "); int year = scanner.nextInt();
int num2 = scanner.nextInt(); if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println(year + " is a leap year.");
int sum = num1 + num2; } else {
System.out.println("Sum: " + sum); System.out.println(year + " is not a leap year.");
}}}
scanner.close(); OUTPUT
}} Enter a year: 2023
OUTPUT 2023 is not a leap year.
Enter first number: 552
Enter second number: 985 7. WAP to display the values from 1 to 5 using FOR loop
Sum: 1537 public class abc {
5. WAP to display the Factorial Calculation of an integer. public static void main(String[] args) {
import java.util.Scanner; int i;
import java.util.Scanner; for (i=1; i <=5; i++){
System.out.println(“” + i);}
public class Factorial { }}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); OUTPUT
System.out.print("Enter a number: "); 1
int num = scanner.nextInt(); 2
int factorial = 1; 3
for (int i = 1; i <= num; i++) { 4
factorial *= i; 5
}
System.out.println("Factorial: " + factorial);
2|P a ge
5
8. WAP to calculate the area of a rectangle. 10. Write a program to find out how many elements an array has, use the
import java.util.Scanner; length property:
public class RectangleArea { public static void main(String[] args) {
public static void main(String[] args) { String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
Scanner scanner = new Scanner(System.in); System.out.println(cars.length);
}
System.out.print("Enter length of rectangle: ");
OUTPUT
double length = scanner.nextDouble();
4
System.out.print("Enter width of rectangle: "); 11. Write a program to create a two-dimensional array, add each array
double width = scanner.nextDouble(); within its own set of curly braces:
public class abcd{
double area = length * width; public static void main(String[] args) {
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
System.out.println("Area of rectangle: " + area); int x = myNumbers[1][2];
System.out.println(x);
scanner.close(); }}
} OUTPUT
} 7
OUTPUT
Enter length of rectangle: 20
12. Write a program to use a for loop inside another for loop to get the
Enter width of rectangle: 15
elements of a two dimensional array
Area of rectangle: 300.0
9. WAP to print first 5 natural numbers using WHILE loop public class ab{
public class Main { public static void main(String[] args) {
public static void main(String[] args) { int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
int i = 0;
for (int i = 0; i < myNumbers.length; ++i) {
while (i <= 5) {
System.out.println(i); for(int j = 0; j < myNumbers[i].length; ++j) {
i++; System.out.println(myNumbers[i][j]);
}}} }}}}
OUTPUT
OUTPUT 1
0 2
1 3
2 4
3 5
4 6
3|P a ge
7 for (int i = 0; i < names.length; i++)
System.out.print(names[i] + ",");
13. Write a program to store five marks in the array
double[]marks = {346, 144, 103, 256.5, 387.5}; System.out.println();
double total_marks = 400; Arrays.sort(names);
System.out.println("\tClass Report");
System.out.println("--------------------------------------"); System.out.println("Names after Sorting:");
System.out.println("RollNo\tMarks\tPercentage\tResult"); for (int i = 0; i < names.length; i++)
System.out.println("--------------------------------------"); System.out.print(names[i] + ",");
for (int i = 0; i <marks.length; i++) { System.out.println(); }}
double percentage = (marks[i]/total_marks)*100;
String result; OUTPUT
if (percentage >= 40) Names Array before Sorting:
result = "Passed"; Hari,Shyam,Ganga,Avani,Manish,Dev,Purvi,Aman,
else Names after Sorting:
result = "Failed"; Aman,Avani,Dev,Ganga,Hari,Manish,Purvi,Shyam,
System.out.print((i+1)+"\t"); 15. Write a program to check Age using call a method with an integer
System.out.print(marks[i]+"\t"); parameter.
System.out.print(percentage+"\t\t"); import java.util.Scanner;
System.out.println(result);} public class CheckAge {
OUTPUT static void checkAge(int age) {
if (age < 18) {
System.out.println("Access denied - You are not old enough!");
} else {
System.out.println("Access granted - You are old enough!");
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
14. Write a program to sort an array of Strings in alphabetic order System.out.print("Enter your age: ");
import java.util.Arrays; int age = scanner.nextInt();
checkAge(age);
public class abc { scanner.close();
public static void main(String args[]) { }
String[] names = {"Hari", "Shyam", "Ganga", "Avani", "Manish", }
"Dev", "Purvi", "Aman"}; OUTPUT
System.out.println("Names Array before Sorting:"); Enter your age: 20
4|P a ge
Access granted - You are old enough!
16. Write a JAVA program to convert an Integer to a String, and use the DATABASE MANAGEMENT SYSTEM USING SQL
length() method of the String class to output the length of the
"string":
import java.util.Scanner; 1. Create a student table with the student id, name, and marks as
attributes where the student id is
public class Main { the primary key.
public static void main(String[] args) { 2. Insert the details of a new student in the above table.
Scanner scanner = new Scanner(System.in); 3. Delete the details of a student in the above table.
4. Use the select command to get the details of the students with
System.out.print("Enter an integer: ");
marks more than 80.
int userInput = scanner.nextInt();
5. Find the min, max, sum, and average of the marks in a student
marks table.
Integer myInt = userInput;
String myString = myInt.toString(); 6. Find the total number of customers from each country in the
System.out.println("Length of the string representation: " + table (customer ID, customer
myString.length()); Name, country) using group by.
7. Write a SQL query to order the (student ID, marks) table in
scanner.close(); // Close the scanner to prevent resource leak descending order of the marks
} 8. Write a SQL query to display the marks without decimal places,
} display the reminder after diving marks by 3 and display the
OUTPUT square of marks
Enter an integer: 5004 9. Write a SQL query to display names into capital letters, small
Length of the string representation: 4 letters, display frist 3 letters of name, display last 3 letters of
name, display the position the letter A in name
10. Remove extra spaces from left, right and both sides from the
text – ” Informatics Practices Class XII “.
11. Display today’s date in “Date/Month/Year” format.
12. Display dayname, monthname, day, dayname, day of month, day
of year for today’s date.
5|P a ge
[1] Create table student [3] Deleting records
delete from student where studentid=5;
[2] Inserting records
[4] Fetching record with criteria
select * from student where marks>80;
Table data:
[5] Maximum, Minimum, Sum and Average of marks
select max(marks), min(marks), sum(marks) , avg(marks) from
student;
6|P a ge
[6] Group by
select country, count(customer_id) from customer group by [9] Text functions
country;
select
[7] Sorting in descending order ucase(name),lcase(name),left(name,3),right(name,3),instr(name,
'a') from student;
select * from student order by marks desc;
[10] Text Functions
select ltrim(" Informatics Practices Class XII ")
"Left Spaces", rtim(" Informatics Practices Class
XII ") "Right Trim", trim(" Informatics Practices
Class XII ");
[8] Math functions
select round(marks,0),mod(marks,3),pow(marks,2) from student;
7|P a ge
[11] Date function in MySQL 13. Queries (Database Fetching records)
select
concat(date(now()),concat("/",concat(month(now()),concat("/",y Consider the following MOVIE table and write the SQL queries based on
ear(now()))))); it.
[12]
select
dayname(now()),monthname(now()),day(now()),dayname(now()),dayo
fmonth(now()),dayofyear(now());
1. Display all information from movie.
2. Display the type of movies.
3. Display movieid, moviename, total_eraning by showing the business done
by the movies. Claculate the business done by movie using the sum of
productioncost and businesscost.
4. Display movieid, moviename and productioncost for all movies with
productioncost greater thatn 150000 and less than 1000000.
5. Display the movie of type action and romance.
6. Display the list of movies which are going to release in February, 2022.
8|P a ge
14. Queries (Based on Two Tables)
9|P a ge
**Find Output of following queries
(v) SELECT M_Id, SUM(M_Qty) FROM MobileStock GROUP BY
M_Id;
MB004 450
MB003 400
MB003 300
MB003 200
(vi) SELECT MAX(M_Mf_Date), MIN(M_Mf_Date) FROM
MobileMaster;
2017-11-20 2010-08-21
(vii) SELECT M1.M_Id, M1.M_Name, M2.M_Qty, M2.M_Supplier
FROM MobileMaster M1, MobileStock M2 WHERE
M1.M_Id=M2.M_Id AND M2.M_Qty>=300;
(i) Display the Mobile company, Mobile name & price
in descending order of their manufacturing date. MB004 Unite3 450 New_Vision
Ans. SELECT M_Compnay, M_Name, M_Price FROM
MobileMaster ORDER BY M_Mf_Date DESC; MB001 Galaxy 300 Classic Mobile Store
(ii) List the details of mobile whose name starts with “S”.
Ans. SELECT * FROM MobileMaster
WHERE M_Name LIKE “S%‟; (viii) SELECT AVG(M_Price) FROM MobileMaster;
5450
(iii) Display the Mobile supplier & quantity of all mobiles
except “MB003‟.
Ans.SELECT M_Supplier, M_Qty FROM MobileStock
WHERE M_Id <>”MB003”;
(iv) To display the name of mobile company having price
between 3000 & 5000.
Ans. SELECT M_Company FROM MobileMaster WHERE M_Price
BETWEEN 3000 AND 5000;
10 | P a g e