How would I search throught the arraylist jobs to find internship type? Please s
ID: 3821383 • Letter: H
Question
How would I search throught the arraylist jobs to find internship type? Please see the below code (arraylist class and tester)
public class Company
{
//instance variables
private String coName, contact, coEmail, jobTitle, jobType, paid, semester;
//constructor method
public Company(){}
//parameterized constructor
public Company (String n, String c, String e, String j, String t, String p, String s)
{coName=n;
contact=c;
coEmail=e;
jobTitle=j;
jobType=t;
paid=p;
semester=s;
}
//set methods
public void setConame(String n)
{
coName=n;
}
public void setContact(String c)
{
contact=c;
}
public void setCoemail(String e)
{
coEmail=e;
}
public void setJobtitle(String j)
{
jobTitle=j;
}
public void setJobtype(String t)
{
jobType=t;
}
public void setPaid(String p)
{
paid=p;
}
public void setSemester(String s)
{
semester=s;
}
//access method
public String getConame()
{
return coName;
}
public String getContact()
{
return contact;
}
public String getCoemail()
{
return coEmail;
}
public String getJobtitle()
{
return jobTitle;
}
public String getJobtype()
{
return jobType;
}
public String getPaid()
{
return paid;
}
public String getSemester()
{
return semester;
}
//display
public String toString()
{
//String coprt=(coName+" "+jobTitle+" "+jobType+" "+paid+" "+semester);
//return coprt;
String s="" + coName + " offers internships for " + jobType;
return s;
}
}
-----------------BREAK---------------------------
/*
1- populate arraylists (if empty ?? -- how is array data retained?)
-- private variables
2- user interface options: 1) display all companies offering...2) display all students wanting...
3)search by internship type, company, student then generate reports
3- methods to enable add / edit / remove records in arraylist (if/else) => how/from where to call these methods?
-- companies, students, internships, ... all data elements?
-- is there simple way to SEARCH? => API Collections
-- RESEARCH: look up list
** REMEMBER CLEAN UP OUTPUT FORMAT **
*/
import java.util.Scanner;
import java.util.ArrayList;
public class InternMatch
{
public static void main (String [] args)
{
//create arrayList1
ArrayList <Company> job = new ArrayList<Company>();
//coName, contact, coEmail, jobTitle, jobType, paid, semester
job.add(new Company ("GE", "V.Williams", "will@ge.com", "HR Manager","Marketing","Y","SP2018"));
job.add(new Company ("IBM", "S.Johnson", "john@ibm.com", "HR Manager","IT","Y","SP2018"));
job.add(new Company ("FDR", "B.Jones", "jone@fdr.com", "HR Manager","HR","N","SU2018"));
job.add(new Company ("Suntrust", "S.Stokes", "stok@suntrust.com", "HR Manager","Sales","Y","F2018"));
//create arrayList2
ArrayList <Student> intern = new ArrayList<Student>();
//String stName, stEmail, jobType, semester;
intern.add(new Student ("Jill Jones", "JJ@KSU.com", "Marketing","SP2018"));
intern.add(new Student ("Mike Smith", "MS@KSU.com", "Sales","F2018"));
intern.add(new Student ("Chin Li", "CL@KSU.com", "Marketing","SP2018"));
intern.add(new Student ("Tammy Jones", "TJ@KSU.com", "Actuary","SP2018"));
intern.add(new Student ("Ngozi Somah", "NS@KSU.com", "IT","SP2018"));
intern.add(new Student ("Yeteva Harris", "YH@KSU.com", "HR","SU2018"));
Scanner input = new Scanner(System.in);
int opt=0;
int array1[] = new int[4];
int array2[] = new int[6];
String type,IT=null, HR, Marketing, Sales;
//accept user input
System.out.print("WELCOME TO THE INTERNSHIP SEARCH PORTAL ");
System.out.println("Please Enter the Number corresponding to One of the Following Options:");
System.out.print(" Enter 1: List of Companies Offering Internships Enter 2: List of Students Seeking Internships");
System.out.print(" Enter 3: Search for Companies Offering A Specified Type of Internship Enter 4: Search for Students Seeking Specified Internship ");
System.out.println("Enter -1 to End Session");
//user input
for(int i=0;i<1;i++)
{
opt=input.nextInt();
}
//loop control
if(opt==-1)
System.out.print("Session Terminated.");
else
if(opt==1)
for(int i=0; i<job.size(); i++)
{
System.out.println(job.get(i).toString());
}
else
if(opt==2)
for(int i=0; i<intern.size(); i++)
{
System.out.println(intern.get(i).toString());
}
else
if(opt==3)
System.out.println("Enter the TYPE of Internship");
//user input
type=input.nextLine();
input.nextLine();
for (Company n: job)
System.out.println(n.toString());
for(int i=0; i<job.size(); i++)
{
if(job.getcoName().equals("IT"))
System.out.println("i: " + i + job.get(i).toString());
}
Explanation / Answer
InternMatch.java
package comjobs;
import java.util.ArrayList;
import java.util.Scanner;
public class InternMatch {
public static void main(String[] args) {
// create arrayList1
ArrayList<Company> job = new ArrayList<Company>();
// coName, contact, coEmail, jobTitle, jobType, paid, semester
job.add(new Company("GE", "V.Williams", "will@ge.com", "HR Manager", "Marketing", "Y", "SP2018"));
job.add(new Company("IBM", "S.Johnson", "john@ibm.com", "HR Manager", "IT", "Y", "SP2018"));
job.add(new Company("FDR", "B.Jones", "jone@fdr.com", "HR Manager", "HR", "N", "SU2018"));
job.add(new Company("Suntrust", "S.Stokes", "stok@suntrust.com", "HR Manager", "Sales", "Y", "F2018"));
// create arrayList2
ArrayList<Student> intern = new ArrayList<Student>();
// String stName, stEmail, jobType, semester;
intern.add(new Student("Jill Jones", "JJ@KSU.com", "Marketing", "SP2018"));
intern.add(new Student("Mike Smith", "MS@KSU.com", "Sales", "F2018"));
intern.add(new Student("Chin Li", "CL@KSU.com", "Marketing", "SP2018"));
intern.add(new Student("Tammy Jones", "TJ@KSU.com", "Actuary", "SP2018"));
intern.add(new Student("Ngozi Somah", "NS@KSU.com", "IT", "SP2018"));
intern.add(new Student("Yeteva Harris", "YH@KSU.com", "HR", "SU2018"));
Scanner input = new Scanner(System.in);
int opt = 0;
int array1[] = new int[4];
int array2[] = new int[6];
String type, IT = null, HR, Marketing, Sales;
// accept user input
System.out.print("WELCOME TO THE INTERNSHIP SEARCH PORTAL ");
System.out.println("Please Enter the Number corresponding to One of the Following Options:");
System.out.print(
" Enter 1: List of Companies Offering Internships Enter 2: List of Students Seeking Internships");
System.out.print(
" Enter 3: Search for Companies Offering A Specified Type of Internship Enter 4: Search for Students Seeking Specified Internship ");
System.out.println("Enter -1 to End Session");
// user input
for (int i = 0; i < 1; i++) {
opt = input.nextInt();
}
// loop control
if (opt == -1)
System.out.print("Session Terminated.");
else if (opt == 1)
for (int i = 0; i < job.size(); i++) {
System.out.println(job.get(i).toString());
}
else if (opt == 2)
for (int i = 0; i < intern.size(); i++) {
System.out.println(intern.get(i).toString());
}
else if (opt == 3)
System.out.println("Enter the TYPE of Internship");
// user input
type = input.nextLine();
input.nextLine();
// for (Company n: job)
// System.out.println(n.toString());
for (int i = 0; i < job.size(); i++) {
if (job.get(i).getJobtype().equals(type))
System.out.println("i: " + i + job.get(i).toString());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.