outprintEnter the name of the Student objectsiName innextLine

Outprintenter the name of the student objectsiname

This preview shows page 1 - 3 out of 3 pages.

System.out.print("Enter the name of the Student: "); objects[i].Name = in.nextLine(); output.println(objects[i].Name);
Image of page 1
System.out.print("Enter the Registration of Number: "); objects[i].RegNo = in.nextLine(); output.println(objects[i].RegNo); System.out.print("Enter the Section: "); objects[i].section = in.nextLine(); output.println(objects[i].section); System.out.print("Enter the CGPA: "); objects[i].CGPA = in.nextFloat(); in.nextLine(); output.println(objects[i].CGPA); output.println(); } output.close(); } public static void part2(Scanner in, int j, Students [] array)throws Exception{ Scanner read = new Scanner(new File("database.txt")); for (int i = 0; i < j; i++) { array[i] = new Students(); array[i].Name = read.nextLine(); array[i].RegNo = read.nextLine(); array[i].section = read.nextLine(); array[i].CGPA = read.nextFloat(); } String name = "null"; if(j!=0) { System.out.print("Enter the name of the Student you want to search: "); name = in.nextLine(); } int index = -1; for (int i = 0; i < j; i++) if (match(array[i].Name, name) == true) index = i; if (index != (-1)) { System.out.println(array[index].Name); System.out.println(array[index].RegNo); System.out.println(array[index].section); System.out.println(array[index].CGPA); } else if (j!=0) System.out.println("The name you entered does not exist in database."); if (j!=0) System.out.println("Type 0 to exit."); else System.out.println("There cannot be 0 students."); } public static boolean match(String x, String y){ boolean flag = true; for (int i=0; i<x.length() || i < y.length(); i++){
Image of page 2
if (flag ==false) break; if(x.charAt(i)==y.charAt(i)) flag= true; else flag=false; } return flag; } } class Students{ String Name; String RegNo; String section; float CGPA; }
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Fall '18
  • main function, String section, public class Assignment

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture