JAVA Cycle Sheet 3 CSE1007
JAVA Cycle Sheet 3 CSE1007
Question:
1. Create database of the student with the details such as (name, registernumber,
cgpa, age, dayscholar/hosteller).
2. Create a class student with the needed attributes. Use array of objects to store ‘n’
number of students’ details into the database.
3. Write a java program to fetch the following details from the database.
a. List of students whose joined in 2018.
b. List of students whose age is between 18-20
c. List of students with CGPA less than 5.
d. List of students who stay in hostel.
e. List of 2019 batch students who are dayscholars.
Code:
import java.io.*;
import java.util.Scanner;
class student {
void getDetails(int n)
int limit=n;
for(int i=0;i<limit;i++)
for(int j=0;j<5;j++)
name[i][j] = get.nextLine();
}
19BCE2168 Aadarsh N Prasad
display(limit);
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
for(int j=0;j<5;j++)
System.out.print(name[i][j]+"\t\t");
System.out.println();
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
if("18".equals(name[i][1].substring(0,2)))
for(int j=0;j<5;j++)
System.out.print(name[i][j]+"\t\t");
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
for(int j=0;j<5;j++)
System.out.print(name[i][j]+"\t\t");
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
if(Integer.parseInt(name[i][2])<=5)
for(int j=0;j<5;j++)
System.out.print(name[i][j]+"\t\t");
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
if("y".equals(name[i][4]) || "Y".equals(name[i][4]))
for(int j=0;j<5;j++)
19BCE2168 Aadarsh N Prasad
System.out.print(name[i][j]+"\t\t");
System.out.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Residence");
for(int i=0;i<limit;i++)
for(int j=0;j<5;j++)
System.out.print(name[i][j]+"\t\t");
class collegeOffice {
int n=0;
int c = in.nextInt();
switch(c)
case 1:
n = in.nextInt();
19BCE2168 Aadarsh N Prasad
std.getDetails(n);
break;
case 2:
std.join2018(n);
break;
case 3:
std.agegap(n);
break;
case 4:
std.gpa(n);
break;
case 5:
std.hostel(n);
break;
case 6:
std.day19(n);
break;
default:
output.println("Student
Name"+"\t"+"Roll"+"\t\t"+"CGPA"+"\t\t"+"Age"+"\t\t"+"Hosteler");
output.println("======================================");
for(int i=0;i<n;i++)
for(int j=0;j<3;j++)
output.print(std.name[i][j]+"\t\t");
output.println();
output.println("======================================");
}
19BCE2168 Aadarsh N Prasad
output.close();
Question:
Given a String as input, perform the following 2 tasks by 2 threads simultaneously without
interrupting each other. Find the cipher text by substituting every letter in the String by the next
letter in the alphabet list Eg., If the input string is “program”, output should be “qsphsbn”. Find the
cipher text by substituting every letter in the String by the previous letter in the alphabet list Eg., If
the input string is “program”, output should be “oqnfqzl”. Both cipher text has to appended to the
same file one after the other.
Code:
import java.lang.*;
import java.util.*;
char ch;
String d,e;
d = multhr.a;
e = "";
for(int i=0;i<d.length();i++)
ch = (char)((int)d.charAt(i)+1);
else if(d.charAt(i)=='z')
ch = 'a';
19BCE2168 Aadarsh N Prasad
else if(d.charAt(i)=='Z')
ch = 'A';
e = e + ch;
System.out.println(e);
char ch;
String f,g;
f = multhr.a;
g = "";
for(int i=0;i<f.length();i++)
ch = (char)((int)f.charAt(i)-1);
else if(f.charAt(i)=='a')
ch = 'z';
else if(f.charAt(i)=='A')
ch = 'Z';
g = g + ch;
System.out.println(g);
a = s.next();
t1.start();
t2.start();