20-07-2018, 09:11 AM
NEED CLASS DIAGRAM FOR BELOW CODE
import java.io.*;
import java.util.Scanner;
import java.util.*;
class StudentRecords1
{
public static void main(String[] args)throws IOException
{
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\t\t\tWelcome to KLE's BCA\t\t\t");
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\t\t\tComplaint registeration\t\t\t");
System.out.println("************************************************************************************************************************************************************************");
Details call= new Details();
call.showMenu();
}
}
class Details
{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name;
int regno,sem;
String complaint,action_taken;
String Date;
public void complaintRegister()throws IOException
{
try
{
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("studentRecords12.txt",true)));
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\tEnter a Student details and register a complaint ");
System.out.println("************************************************************************************************************************************************************************");
boolean addMore=false;
String s;
do
{
System.out.print("Enter your Register Number : ");
regno=Integer.parseInt(br.readLine());
BufferedReader file =new BufferedReader(new FileReader("studentRecords12.txt"));
String filedata;
boolean b=false;
while((filedata=file.readLine())!=null)
{
if(filedata.startsWith(String.valueOf(regno).toString()))
{
System.out.println("Data exist with same Regno");
b=true;
break;
}
}
file.close();
if(b!=true)
{
System.out.print("Enter your Name : ");
name=br.readLine();
System.out.print("Enter your Semister : ");
sem=Integer.parseInt(br.readLine());
System.out.print("Enter a date format(dd/mm/yyyy): ");
Date=br.readLine();
System.out.print("Select a Complaint type as listed below \n1 : Library \n2 : Laboratory \n3 : Faculty\n4 : others\n\nEnter your choice : ");
int cho;
cho=Integer.parseInt(br.readLine());
switch(cho)
{
case 1:System.out.println("Enter your Complaint : ");
complaint=br.readLine();
pw.println(regno);
pw.println(name);
pw.println(sem);
pw.println(Date);
pw.println(complaint);
break;
case 2:System.out.println("Enter your Complaint : ");
complaint=br.readLine();
pw.println(regno);
pw.println(name);
pw.println(sem);
pw.println(Date);
pw.println(complaint);
break;
case 3:System.out.println("Enter your Complaint : ");
complaint=br.readLine();
pw.println(regno);
pw.println(name);
pw.println(sem);
pw.println(Date);
pw.println(complaint);
break;
case 4:System.out.println("Enter your Complaint : ");
complaint=br.readLine();
pw.println(regno);
pw.println(name);
pw.println(sem);
pw.println(Date);
pw.println(complaint);
break;
default: System.out.println("Enter a valid number");
break;
}
}
System.out.print("\n Record added succesfully!!!\n\nDo you want to add more record?(y/n) : ");
s=br.readLine();
if(s.equalsIgnoreCase("y"))
{
addMore=true;
System.out.println();
}
else
{
addMore=false;
}
}while(addMore);
pw.close();
}
catch(Exception e)
{
System.out.println("Error found");
}
showMenu();
}
public void toTakeAction()throws IOException
{
try
{
PrintWriter pw1 = new PrintWriter(new BufferedWriter(new FileWriter("studentRecords22.txt",true)));
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\tTo action for registered complaint ");
System.out.println("************************************************************************************************************************************************************************");
String Username,Password;
Username="bca";
Password="123";
System.out.print("Login"+"\n");
//Scanner input = new Scanner(System.in);
DataInputStream dis=new DataInputStream(System.in);
System.out.print("Enter a Username: ");
String username = dis.readLine();
Scanner input1 = new Scanner(System.in);
System.out.print("Enter a Password: ");
String password =dis.readLine();
if(username.equals(Username) && password.equals(Password))
{
System.out.println("you are logged in");
String name,s1;
boolean addMore1=false;
boolean b1=false;
String r1,rn;
System.out.print("Enter your register number :");
regno=Integer.parseInt(br.readLine());
do
{
String filedata1;
boolean b=false;
BufferedReader file5 = new BufferedReader(new FileReader("studentRecords12.txt"));
while((r1=file5.readLine())!=null)
{
if(r1.equals(String.valueOf(regno).toString()))
{
System.out.println("Register Number : " +regno);
System.out.println("Name : " +file5.readLine());
System.out.println("Semister : " +file5.readLine());
System.out.println("Date : " +file5.readLine());
System.out.println("Complaint registered : " +file5.readLine());
}
}
System.out.print("Enter your Action taken to be taken for given complaint : ");
action_taken=br.readLine();
pw1.println(regno);
pw1.println(action_taken);
System.out.println();
System.out.print("\n Record added succesfully!!!\n\nDo you want to add more record?(y/n): ");
s1=br.readLine();
if(s1.equalsIgnoreCase("y"))
{
addMore1=true;
System.out.println();
}
else
{
addMore1=false;
}
}while(addMore1);
pw1.close();
}
else if(username.equals(Username))
{
System.out.println("Invalid username");
}
else if(password.equals(Password))
{
System.out.println("Invalid Password");
}
else
{
System.out.println("Invalid Username and Password");
}
}
catch(Exception e)
{
System.out.println("Error found");
}
showMenu();
}
public void display()throws IOException
{
try
{
BufferedReader file6 = new BufferedReader(new FileReader("studentRecords12.txt"));
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\tDisplaying the records ");
System.out.println("************************************************************************************************************************************************************************");
int i=1;
String r;
while((r=file6.readLine())!=null)
{
System.out.println("S.No :"+(i++));
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
regno=Integer.parseInt®;
System.out.println("Register Number : " +regno);
System.out.println("Name : " +file6.readLine());
System.out.println("Semister : " +file6.readLine());
System.out.println("Date : " +file6.readLine());
System.out.println("Complaint registered : " +file6.readLine());
BufferedReader file1 = new BufferedReader(new FileReader("studentRecords22.txt"));
String rn;
while((rn=file1.readLine())!=null)
{
if(rn.equals(String.valueOf(regno).toString()))
{
regno=Integer.parseInt(rn);
System.out.println("Action taken for complaint: " +file1.readLine());
file1.close();
break;
}
}
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
}
file6.close();
showMenu();
}
catch(FileNotFoundException e)
{
System.out.println("\n ERROR : File not found!!");
}
}
public void counting()throws IOException
{
try
{
BufferedReader files = new BufferedReader(new FileReader("studentRecords12.txt"));
BufferedReader files1 = new BufferedReader(new FileReader("studentRecords22.txt"));
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\tCounting a number of complaints and action taken ");
System.out.println("************************************************************************************************************************************************************************");
int count=0,count1=0;
String c1;
while((c1=files.readLine())!=null)
{
name=c1;
Date=c1;
complaint=c1;
if(c1.equals(String.valueOf(regno).toString()))
{
regno=Integer.parseInt(c1);
//regno=c1;
c1=files.readLine();
}
c1=files.readLine();
c1=files.readLine();
c1=files.readLine();
c1=files.readLine();
count++;
}
System.out.println("Number of complaint registered are : "+count);
files.close();
String ac;
while((ac=files1.readLine())!=null)
{
action_taken=ac;
ac=files1.readLine();
count1++;
}
System.out.println("Number of complaint action taken are : "+count1);
files1.close();
}
catch(Exception e)
{
System.out.println("Error found");
}
showMenu();
}
public void search()throws IOException
{
System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\t\tSearching for a particular Student record");
System.out.println("************************************************************************************************************************************************************************");
try
{
String rgn;
System.out.print("Enter your register number :");
regno=Integer.parseInt(br.readLine());
BufferedReader file =new BufferedReader(new FileReader("studentRecords12.txt"));
BufferedReader file2 =new BufferedReader(new FileReader("studentRecords22.txt"));
while((rgn=file.readLine())!=null)
{
if(rgn.equals(String.valueOf(regno).toString()))
{
regno=Integer.parseInt(rgn);
System.out.println("Register Number : " +regno);
System.out.println("Name : " +file.readLine());
System.out.println("Semister : " +file.readLine());
System.out.println("Date : " +file.readLine());
System.out.println("Complaint registered : " +file.readLine());
break;
}
}
String rgn1;
while((rgn1=file2.readLine())!=null)
{
if(rgn1.equals(String.valueOf(regno).toString()))
{
regno=Integer.parseInt(rgn1);
System.out.println("Action taken for complaint : " +file2.readLine());
//file2.close();
break;
}
}
//file.close();
}
catch(Exception e)
{
System.out.println("Error found");
}
showMenu();
}
public void showMenu()throws IOException
{
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
System.out.println("Select a any one option as listed below :");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
System.out.print("1 : Student to register thier details and complaint \n2 : Action taken \n3 : Display Record\n4 : Count a number of complaint registered and action taken \n5 : Search \n6 : Exit \n");
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
System.out.print("Enter your choice : ");
int choice = Integer.parseInt(br.readLine());
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
switch(choice)
{
case 1: complaintRegister();
break;
case 2: toTakeAction();
break;
case 3: display();
break;
case 4: counting();
break;
case 5: search();
break;
case 6: System.out.println("************************************************************************************************************************************************************************");
System.out.println("\t\t\t\t\t\t\t\t\tThank you ");
System.out.println("************************************************************************************************************************************************************************");
System.exit(1);
break;
default:System.out.println("\n Invalid choice!!!");
break;
}
System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
}
}