Uploaded by praveenraj2001.007

javafat

advertisement
JAVA PROGRAMMING
LAB
FAT
PRAVEEN RAJ M
19BCE0685
6.. (a) Biometric attendance of students are stored in an Arraylist in
the form of their 4 digit id’s. Problem is students aren’t aware that
their fingerprint is accepted the machine or not so chances of giving
biometric them twice or more than twice. You are expected to write a
code to just store the only one id’s of students without repeating it
and display it.
Code:
import java.util.ArrayList;
import java.util.Scanner;
public class Biocheck {
public static void main(String[] args) {
System.out.println("FINAL ASSESSMENT JAVA\nPraveen Raj M\n19BCE0685");
int choice=1;
int n,j;
Scanner s=new Scanner(System.in);
ArrayList<Integer> bio = new ArrayList<Integer>();
System.out.println("\n enter the biometric numbers to be checked:");
while(choice==1)
{
n=s.nextInt();
j=0;
for (int i = 0; i < bio.size(); i++)
{
if(n==bio.get(i))
{j=1;
break;}
}
if(j==0 && n<=9999)
{bio.add(n);}
System.out.println("\nenter 1 if you have one more number to be checked:");
choice=s.nextInt();
}
System.out.println("\nSO VALID BIOMETRIC ID'S OF STUDENTS PRESENT ARE:\n");
for (int i = 0; i < bio.size(); i++)
{ System.out.println(bio.get(i) + " "); }
}
}
(b) There are 22 and 10 instructional days for a particular course before Mid-term and
Termend examinations respectively. Declare a 2-dimensional jagged array with 2 rows to
store the entire attendance details of a single student in that course, where in the first row
must have 22 elements, second row- 10 elements. Assuming the array elements contain any
of the 2 values ‘1’ / ‘0’ denoting Present/Absent, write a program to evaluate the attendance
percentage for his Mid-term and Term-end period (all the two terms taken together). Use
enhanced-for loops to traverse the array.
B]
CODE:
import java.util.Scanner;
public class Checkattendance {
public static void main(String[] args) {
System.out.println("FINAL ASSESSMENT JAVA\nPraveen Raj M\n19BCE0685");
int arr[][] = new int[2][];
arr[0] = new int[22];
arr[1] = new int[10];
float attpm=0,attpe=0;
float total=0,total1=0,total2=0,j=0;
Scanner s=new Scanner(System.in);
System.out.println("Enter the attendance of the student-- for mid term \n");
for(int i=0;i<22;i++)
arr[0][i]=s.nextInt();
System.out.println("Enter the attendance of the student-- for term end \n");
for(int i=0;i<10;i++)
arr[1][i]=s.nextInt();
for (int[] arr1D : arr) {
for (int i : arr1D) {
if(i==1)
{
total=total+1;
}
j++;
}
if(j==22)
{
total1=total;
attpm=(total/22)*100;
}
if(j==32)
{
total2=total-total1;
attpe=(total2/10)*100;
}
}
float attpt=(total/32)*100;
System.out.println("ATTENDANCE PERCENTAGE FOR MID TERM FOR THE STUDENT IS:"+
attpm);
System.out.println("ATTENDANCE PERCENTAGE FOR TERM END FOR THE STUDENT IS:"+
attpe);
System.out.println("ATTENDANCE PERCENTAGE FOR THE SEMESTER FOR THE STUDENT
IS:"+attpt);
}
}
Download