Java Programming Problem 03-27-2014, 03:07 PM
#1
Hi,
I am helping a friend with her Java Programming project. The program is simple, it will:
1. Display Employee Information
2. Can do Searching by EmployeeID
Here's the code I created and I am experiencing:
I also want to implement a search() method but I don't know how but I have something in mind.
1. Maybe I will make the items in the txt file to become an array and return the whole line with employee information if it finds a match in employee ID.
2. Will simply go through each line and return the whole line when a match is found.
Note: It's a separated value with _ or *
Here's my code:
In the text file:
with the format:
firstName_lastName*employeeID*rank*sallary
Every idea is welcome and appreciated. I hope someone will care to help. Thank you so much.
I am helping a friend with her Java Programming project. The program is simple, it will:
1. Display Employee Information
2. Can do Searching by EmployeeID
Here's the code I created and I am experiencing:
Code:
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:349)
at MyCoc.showAll(MyCoc.java:62)
at MyCoc.main(MyCoc.java:22)I also want to implement a search() method but I don't know how but I have something in mind.
1. Maybe I will make the items in the txt file to become an array and return the whole line with employee information if it finds a match in employee ID.
2. Will simply go through each line and return the whole line when a match is found.
Note: It's a separated value with _ or *
Here's my code:
Code:
import java.io.*;
import java.util.*;
import java.util.ArrayList;
public class MyCoc {
static String fileName = "Employee.txt";
public static void main(String[] args) {
// TODO, add your application code
//System.out.println("Hello World!");
int menuItem = -1;
while (menuItem != 0){
menuItem = menu();
switch(menuItem){
case 1:
showAll();
break;
case 2:
searchID();
break;
case 3:
break;
default:
System.out.println("Invalid Input. Please Try Again");
}
}
}
static int menu(){
int choice;
Scanner userChoice = new Scanner(System.in);
System.out.println("");
System.out.println(" EMPLOYEE PROFILE ");
System.out.println(" --------------------------------------------- ");
System.out.println(" 1. Display Employees ");
System.out.println(" 2. Search by ID ");
System.out.println(" 3. ######## ");
System.out.println(" 0. Exit ");
System.out.println(" ********************************************* ");
System.out.println("");
System.out.print("Please select a transaction to process: ");
choice = userChoice.nextInt();
return choice;
}
static void showAll(){ //choice #1
String line;
StringTokenizer y=new StringTokenizer(line,"_*");
String id=y.nextToken();
String lastname=y.nextToken();
String firstname=y.nextToken();
String position=y.nextToken();
String rank=y.nextToken();
String s=y.nextToken();
System.out.println(" Employee ID :"+id );
System.out.println(" Last Name :"+lastname );
System.out.println(" First Name :"+firstname );
System.out.println(" Position :"+position );
System.out.println(" Rank :"+rank );
System.out.println ("");
System.out.println(" ********************************************* ");
}
static void searchID(){
}
}In the text file:
Code:
Jamie_Sullivan*2006-0031*Worker*2*350.00
John_Smith*2001-0001*Manager*3*450.00
Tim_Jones*2010-0008*Worker*1*260.00
Kimmy_Dora*2009-0021*Worker*2*350.00with the format:
firstName_lastName*employeeID*rank*sallary
Every idea is welcome and appreciated. I hope someone will care to help. Thank you so much.




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)
