Java Practical File PDF
Document Details
SRM Institute of Science & Technology
Lakshika Sharma
Tags
Summary
This is a Java programming practical file from SRM Institute of Science & Technology. It contains a list of programs designed for computer applications students.
Full Transcript
**SRM INSTITUTE OF SCIENCE & TECHNOLOGY** **DELHI-NCR CAMPUS, MODINAGAR** **(FACULTY OF SCIENCE & HUMANITIES)** **DEPARTMENT OF COMPUTER APPLICATION** **Practical File** **[Programming using Java]** **[(PCA20C01J)]** **MCA I Year** **Session: Aug 2024 - Nov 2024** **[Submitted To:] [Submitt...
**SRM INSTITUTE OF SCIENCE & TECHNOLOGY** **DELHI-NCR CAMPUS, MODINAGAR** **(FACULTY OF SCIENCE & HUMANITIES)** **DEPARTMENT OF COMPUTER APPLICATION** **Practical File** **[Programming using Java]** **[(PCA20C01J)]** **MCA I Year** **Session: Aug 2024 - Nov 2024** **[Submitted To:] [Submitted By:]** **Ms. Vaishali Gupta Lakshika Sharma** **Assistant Professor 24231003733** **MCA Department** +-------------+-------------+-------------+-------------+-------------+ | S.NO | PROGRAMS | DATE | **P.NO.** | **REMARKS** | | ==== | ======== | ==== | ========= | =========== | +=============+=============+=============+=============+=============+ | **1.** | **Program | | | | | | to accept | | | | | | student | | | | | | details** | | | | | | | | | | | | **And | | | | | | display | | | | | | them** | | | | +-------------+-------------+-------------+-------------+-------------+ | **2.** | **Program | | | | | | to print | | | | | | pattern** | | | | +-------------+-------------+-------------+-------------+-------------+ | **3.** | **Program | | | | | | to print | | | | | | table from | | | | | | 1 to | | | | | | accepted | | | | | | no.** | | | | +-------------+-------------+-------------+-------------+-------------+ | **4.** | **Program | | | | | | to check | | | | | | input is | | | | | | part of | | | | | | Fibonacci | | | | | | or not** | | | | +-------------+-------------+-------------+-------------+-------------+ | **5.** | **Program | | | | | | to accept | | | | | | 10 integers | | | | | | and store | | | | | | them in an | | | | | | array and | | | | | | perform | | | | | | operations* | | | | | | * | | | | +-------------+-------------+-------------+-------------+-------------+ | **6.** | **Program | | | | | | to create | | | | | | calculator | | | | | | using | | | | | | classes and | | | | | | methods** | | | | +-------------+-------------+-------------+-------------+-------------+ | **7.** | **Program | | | | | | to call | | | | | | method of | | | | | | other | | | | | | class** | | | | +-------------+-------------+-------------+-------------+-------------+ | **8.** | **Program | | | | | | to perform | | | | | | string | | | | | | operations* | | | | | | * | | | | +-------------+-------------+-------------+-------------+-------------+ | **9.** | **Program | | | | | | to check | | | | | | variable | | | | | | capacity** | | | | +-------------+-------------+-------------+-------------+-------------+ | **10.** | **Program | | | | | | to accept | | | | | | and display | | | | | | value of | | | | | | data member | | | | | | on output | | | | | | device** | | | | +-------------+-------------+-------------+-------------+-------------+ | **11.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **12.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **13.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **14.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **15.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **16.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **17.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **18.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **19.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **20.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **21.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **22.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **23.** | | | | | +-------------+-------------+-------------+-------------+-------------+ | **24.** | | | | | +-------------+-------------+-------------+-------------+-------------+ - **[Program 1]** **[AIM]** - **write a following Java program details to accept about a student and display in readable format :** **(A) Roll no.** **(b) Full Name Address** **(C) Address** **(d) marks in 5 subjects** **(e) Percentage (total)** **[PROCEDURE]** - 1. Import the java.util.Scanner class to read user input from the console. 2. Instantiate a Scanner object to handle input. 3. Prompt the user to enter the roll number and read the integer input. 4. Prompt the user to enter the address and read the string input. 5. Prompt the user to enter the full name and read the string input. 6. Initialize an array to store marks for 5 subjects. 7. Use a loop to prompt the user to enter marks for each subject and accumulate the total marks. 8. Compute the percentage based on the total marks out of 500 (assuming each subject is out of 100). 9. Print all the collected details: roll number, full name, address, individual subject marks, total marks, and percentage. 10. Close the Scanner object to release resources. **[CODE]** - import java.util.Scanner; public class StudentDetails { public static void main(String\[\] args) { Scanner scanner = new Scanner(System.in); System.out.print(\"Enter Roll No: \"); int rollNo = scanner.nextInt(); scanner.nextLine(); // Consume newline System.out.print(\"Enter Full Name: \"); String fullName = scanner.nextLine(); System.out.print(\"Enter Address: \"); String address = scanner.nextLine(); double\[\] marks = new double\[5\]; double totalMarks = 0; System.out.println(\"Enter marks in 5 subjects:\"); for (int i = 0; i \< 5; i++) { System.out.print(\"Subject \" + (i + 1) + \": \"); marks\[i\] = scanner.nextDouble(); totalMarks += marks\[i\]; } double percentage = (totalMarks / 500) \* System.out.println(\"\\nStudent Details:\"); System.out.println(\"Roll No: \" + rollNo); System.out.println(\"Full Name: \" + fullName); System.out.println(\"Address: \" + address); System.out.println(\"Marks in 5 subjects:\"); for (int i = 0; i \< 5; i++) { System.out.println(\"Subject \" + (i + 1) + \": \" + marks\[i\]); } System.out.println(\"Total Marks: \" + totalMarks); System.out.println(\"Percentage: \" + percentage + \"%\"); scanner.close(); } } **[OUTPUT]** - ![](media/image2.jpg) **[RESULT]** - Accepted and displayed the student details successfully. - **[Program 2]** **[AIM -]** **Draw the following pattern :** **\*** **\*\*\*** **\*\*\*\*\*** **\*\*\*\*\*\*\*** **\*\*\*\*\*** **\*\*\*** **\*** **[PROCEDURE]**- 1. No additional imports are needed as we\'re using standard output. 2. Declare the class Pattern. 3. Define the main method which is the entry point of the program. 4. Initialize an integer variable n to determine the height of the top part of the pattern. 5. Loop through i from 0 to n-1 to create the upper half of the pattern. 6. Use a nested loop to print spaces. The number of spaces is calculated as (n - i - 1) \* 3 for each row. 7. Use another nested loop to print stars. The number of stars is (2 \* i + 1) for each row. 8. Loop through i from n-2 to 0 to create the lower half of the pattern. 9. Use a nested loop to print spaces. The number of spaces is calculated as (n - i - 1) \* 3 for each row. 10. Use another nested loop to print stars. The number of stars is (2 \* i + 1) for each row. 11. Compile and run the program to see the pattern printed in the console. **[CODE -]** public class Pattern { public static void main(String\[\] args) { int n = 4; for (int i = 0; i \< n; i++) { for (int j = 0; j \< (n - i - 1) \* 3; j++) { System.out.print(\" \"); } for (int k = 0; k \< (2 \* i + 1); k++) { System.out.print(\"\*\"); } System.out.println(); } for (int i = n - 2; i \>= 0; i\--) { for (int j = 0; j \< (n - i - 1) \* 3; j++) { System.out.print(\" \"); } for (int k = 0; k \< (2 \* i + 1); k++) { System.out.print(\"\*\"); } System.out.println(); } } } **[OUTPUT-]** **[RESULT]**- Displayed the pattern successfully. - **[Program 3]** **[AIM-] Write a java program to print tables from 1 to accepted numbers, using loops and keyboard inputs.** **[PROCEDURE-]** 1. Create scanner class. 2. Prompt user for input. 3. Create outer loop. 4. Create inner loop. 5. Format output. 6. Compile and run. **[CODE-]** import java.util.Scanner; public class MultiplicationTables { public static void main(String\[\] args) { Scanner scanner = new Scanner(System.in); System.out.print(\"Enter the number up to which you want the multiplication tables: \"); int n = scanner.nextInt(); for (int i = 1; i \