Hi , I am totally new to Java . I need someone to provide this question with code answer so that I can learn from your code . Thank you.

Question 1 :

Store 20 integer employee ID numbers in an integer array and 20 corresponding employee last names in a String array. Use dialog boxes to accept an ID number, and display the appropriate name.

jwenting commented: homework kiddo -3

Recommended Answers

All 2 Replies

Here is my code but need some modification
1. use dialog boxes

import java.util.Scanner; 
import javax.swing.*; 

public class EmployeeArray { 

public static void main(String[] args) { 

final int MAX = 20; 

Scanner keybd = new Scanner(System.in); 

int[] ID = new int[MAX]; 
String[] lastName = new String[MAX]; 

boolean found = false; 
int id = 0; 
int c=0; 

for (int i=0; i<MAX; i++) { 
System.out.println("Enter ID number: "); 
ID[i] = keybd.nextInt(); 
System.out.println("Enter last name: "); 
lastName[i] = keybd.next(); 
} // end for 

id = Integer.parseInt( JOptionPane.showInputDialog( "ID number?")); 

do { 
if (ID[c] == id) { 
found = true; 
break; 
} // end if 
c++; 
} while (c<MAX); 

if (found) { 
JOptionPane.showMessageDialog( null, "Last name is "+lastName[c]); 
} else { 
JOptionPane.showMessageDialog( null, "Unknown ID: "+id); 
} // end if 

} // end main() 
} // end class EmployeeArray

See my reply to your other post. We DO NOT do your homework for you! :-(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.