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

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

Jump to Post

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; 
} // end if 
} 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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.