Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, how can I make the below code say invalid input please try again to offer user another chance if they do not put

In Java, how can I make the below code say invalid input please try again to offer user another chance if they do not put in applicant, employer or job for keyword search?

TestMain.java

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.util.Scanner;

/**

* @author Lokesh Kumar

*

*/

public class TestMain {

public static void storeData(Employers[] emp,Applicants[] app,Jobs[] job){

File dataFile;

BufferedWriter writer;

try{

dataFile = new File("E://Data.txt");

if (!dataFile.exists()) {

dataFile.createNewFile();

} else {

dataFile.delete();

dataFile.createNewFile();

writer = new BufferedWriter(new FileWriter(dataFile, true));

int i = 0;

for (Employers employers : emp) {

if (i > 0) {

writer.newLine();

}

writer.write("Employer," + employers.getFirstName() + "," + employers.getLastName() + ","

+ employers.getEmail() + "," + employers.getNumber() + "," + employers.getAge() + ","

+ employers.getExperience() + "," + employers.getCity() + "," + employers.getCompany() + ","

+ employers.getRole());

i++;

}

for (Applicants applicants : app) {

if (i > 0) {

writer.newLine();

}

writer.write("Applicant," + applicants.getFirstName() + "," + applicants.getLastName() + ","

+ applicants.getEmail() + "," + applicants.getNumber() + "," + applicants.getAge() + ","

+ applicants.getQualification() + "," + applicants.getExperience() + ","

+ applicants.getCity() + "," + applicants.getRole());

}

for (Jobs jobs : job) {

if (i > 0) {

writer.newLine();

}

writer.write("Job," + jobs.getCompany() + "," + jobs.getEmail() + "," + jobs.getSalary() + ","

+ jobs.getExperience() + "," + jobs.getCity() + "," + jobs.getRole());

}

writer.close();

}

} catch (Exception exception) {

System.out.println(exception.getMessage());

}

}

public static void search(String keyWord) {

FileReader fr;

BufferedReader br;

try {

fr = new FileReader("E://Data.txt");

br = new BufferedReader(fr);

String line;

int j=1;

while ((line = br.readLine()) != null) {

String[] array = line.split(",");

if (keyWord.equalsIgnoreCase((array[0]))) {

System.out.println("----------------------------------");

System.out.println(array[0] + " : "+j);

for (int i = 1; i < array.length; i++) {

System.out.println(array[i]);

}

j=j+1;

}

}

br.close();

} catch (Exception exception) {

System.out.println(exception.getMessage());

}

}

public static void main(String[] args) {

Employers[] emp = new Employers[5];

Applicants[] app = new Applicants[5];

Jobs[] job = new Jobs[5];

// create employee

emp[0] = new Employers("Nath", "Muellner", "nmuellner@technopark.com", "1-213-233-9474", 37, 10, "LA",

"TechnoPark", "HR");

emp[1] = new Employers("Mark", "Jamison", "mjamison@itpark.com", "1-213-262-7463", 35, 5, "LA", "ITPark",

"Manager");

emp[2] = new Employers("Paul", "Gregory", "pgregory@technicalinnovations.com", "1-213-343-2312", 43, 12, "LA",

"Technical Innovations", "Manager");

emp[3] = new Employers("Harrison", "Jones", "jharrison@sebring.com", "1-213-234-4332", 34, 4, "LA",

"Sebring Techonologies", "HR");

emp[4] = new Employers("Chris", "Lawrence", "clawrence@createch.com", "1-213-231-3532", 29, 2, "LA", "Createch",

"Manager");

// create applicants

app[0] = new Applicants("Samantha", "Michaels", "smichaels@hotmail.com", "1-213-212-2321", 30, "BS", 5, "LA",

"Programmer");

app[1] = new Applicants("George", "Peterson", "gpeterson@yahoo.com", "1-212-434-2322", 24, "MBA", 3, "LA",

"Manager");

app[2] = new Applicants("Katie", "Harris", "kharris@hotmail.com", "1-213-232-1112", 28, "BS", 5, "LA",

"Database Administrator");

app[3] = new Applicants("Kevin", "Reynolds", "kreynolds78@hotmail.com", "1-213-653-2313", 39, "MS", 12, "LA",

"Lead Programmer");

app[4] = new Applicants("Renee", "Collins", "rcollins@aol.com", "1-213-456-4352", 47, "MS", 14, "LA", "CEO");

//Create job postings

job[0] = new Jobs("Technical Innovations", "pgregory@technicalinnovations.com", 75000.23, 5, "LA", "Manager");

job[1] = new Jobs("Sebring Technologies", "jharrison@sebring.com", 100000.40, 5, "LA", "Lead Programmer");

job[2] = new Jobs("IT Park", "mjamison@itpark.com", 85000.23, 3, "LA", "Database Administrator");

job[3] = new Jobs("Createch", "clawrence@createch.com", 70000.24, 3, "LA", "Network Administrator");

job[4] = new Jobs("TechnoPark", "nmuellner@technopark.com", 80000.00, 2, "LA", "Manager");

TestMain.storeData(emp, app, job);

System.out.println("Enter a keyword to search ");

System.out.println("Employer Applicant Job ");

Scanner scanner = new Scanner(System.in);

String keyWord = scanner.next();

TestMain.search(keyWord);

scanner.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

Apply your own composing style to personalize your messages.

Answered: 1 week ago

Question

Format memos and e-mail properly.

Answered: 1 week ago