I'm trying to get the program to carry on through the program, however, there is an error, please see below:
It seems the input is wrong when I enter options 4 and 5. I was hoping you could please review my code and see if you find anything sinister.
Yet, there is more code to be executed (see attached code) for the Main
class:
System.out.println("1.JOB SEEKER\n2.JOB PROVIDER\nENTER YOUR CHOICE");
choice=obj.nextInt();
if(choice==1)
{
while(true)
{
while(flag)
{
System.out.println("\n Menu");
System.out.println("1. ADD YOUR RESUME");
System.out.println("2.TO SEARCH AND GENERATE PRINT OUT OF YOUR RESUME ");
System.out.println("3.TO UPDATE YOU DETAILS ");
System.out.println("4.TO SHOW ALL JOBS \n5.TO SHOW BEST JOB\n6.QUIT");
System.out.print("Enter your choice: ");
choice = obj.nextInt();
switch (choice) {
case 1:
FileWriter fout = new FileWriter("job2.txt", true);
for (i = 0; i < 1; i++) {
System.out.print("enter phno: ");
record2.phno = obj.nextInt();
System.out.print("Enter name:");
record2.name = obj.next();
System.out.print("Enter degree:");
record2.deg = obj.next();
System.out.println("Enter your percentage");
record2.eduper=obj.nextInt();
System.out.print("Enter place:");
record2.add = obj.next();
System.out.println("enter sal");
record2.expsal = obj.nextInt();
fout.write(record2.phno + " \n");
fout.write(record2.name + " \n");
fout.write(record2.deg + " \n");
fout.write(record2.eduper + " \n");
fout.write(record2.add + " \n");
fout.write(record2.expsal + " \n");
}
fout.write("\r\012");
fout.close();
System.out.println("File is created");
break;
case 2:
i=0;
System.out.print("enter phno: ");
double phno = obj.nextInt();
FileReader fin = new FileReader("job2.txt");
Scanner sc = new Scanner(fin);
while (sc.hasNextFloat()) {
record2.phno = sc.nextInt();
record2.name = sc.next();
record2.deg = sc.next();
record2.eduper=sc.nextInt();
record2.add = sc.next();
record2.expsal = sc.nextInt();
if (phno == record2.phno) {
i++;
System.out.println(+i);
record2.displayRecord();
}
}
if(i==0)
{
System.out.println("no resume found ");
break;
//fin.close();
}
fin.close();
int k1=0;
FileReader fin34 = new FileReader("job2.txt");
Scanner sc3 = new Scanner(fin34);
while (sc3.hasNextInt()) {
record2.phno = sc3.nextInt();
record2.name = sc3.next();
record2.deg = sc3.next();
record2.eduper=sc3.nextInt();
record2.add = sc3.next();
record2.expsal = sc3.nextInt();
if (phno == record2.phno) {
k1++;
if(i==k1)
{
// System.out.println(+k);
record2.displayRecord();
break;
}
}
}
break;
case 3:
i=0;
System.out.print("enter phno: ");
phno = obj.nextDouble();
FileReader fin1 = new FileReader("job2.txt");
Scanner sc1 = new Scanner(fin1);
while (sc1.hasNextFloat()) {
record2.phno = sc1.nextInt();
record2.name = sc1.next();
record2.deg = sc1.next();
record2.eduper=sc1.nextInt();
record2.add = sc1.next();
record2.expsal = sc1.nextInt();
if(phno==record2.phno)
{
i++;
}
}
if(i==0)
{
System.out.println("no resume found ");
break;
//fin.close();
}
k1=0;
FileReader fin4 = new FileReader("job2.txt");
Scanner sc4 = new Scanner(fin4);
while (sc4.hasNextFloat()) {
record2.phno = sc4.nextInt();
record2.name = sc4.next();
record2.deg = sc4.next();
record2.eduper=sc4.nextInt();
record2.add = sc4.next();
record2.expsal = sc4.nextInt();
if (phno == record2.phno) {
k1++;
if(i==k1)
{
record2.displayRecord();
break;
}
}
}
System.out.println("press 1 to continue else 0");
choice=obj.nextInt();
if(choice==1)
{
FileWriter fout1 = new FileWriter("job2.txt", true);
for (i = 0; i < 1; i++) {
System.out.print("Enter name:");
record2.name = obj.next();
System.out.print("Enter degree:");
record2.deg = obj.next();
System.out.println("Enter your percentage");
record2.eduper=obj.nextInt();
System.out.print("Enter place:");
record2.add = obj.next();
System.out.println("enter sal");
record2.expsal = obj.nextInt();
fout1.write(record2.phno + " \n");
fout1.write(record2.name + " \n");
fout1.write(record2.deg + " \n");
fout1.write(record2.eduper + " \n");
fout1.write(record2.add + " \n");
fout1.write(record2.expsal + " \n");
}
fout1.write("\r\012");
fout1.close();
System.out.println("YOUR RESUME IS UPDATED");
fin1.close();
}
break;
case 4:
System.out.print("enter degree ");
String cname1 = obj.next();
FileReader fin11 = new FileReader("job3.txt");
Scanner sc11 = new Scanner(fin11);
while(sc11.hasNextFloat())
{
record1.phno = sc11.nextDouble();
record1.cname = sc11.next();
record1.degreq= sc11.next();
record1.reqper=sc11.nextInt();
record1.add=sc11.next();
record1.sal=sc11.nextInt();
if(cname1.equals(record1.degreq))
{
record1.displayRecord();
phno3++;
}
}
fin11.close();
if(phno3==0)
{
System.out.println("no job found");
}