Question: JAVA import java.util.Scanner; public class LE62 { public static void main(String[] args) { int size=arraySize(); //Get array size String userNames[]=setUserNames(size); //Input userNames //PrintUserInfo by passing

JAVA JAVA import java.util.Scanner; public class LE62 { public static void main(String[] args)

import java.util.Scanner;

public class LE62 {

public static void main(String[] args) {

int size=arraySize(); //Get array size

String userNames[]=setUserNames(size); //Input userNames

//PrintUserInfo by passing setUserIDs as argument

//Which will return userIDs array

printUserInfo(setUserIDs(userNames),userNames);

}

private static int arraySize() {

Scanner scan=new Scanner(System.in); //Scanner class object to get user input

System.out.printf("How many users? "); //Ask user to enter size

int size=scan.nextInt();

return size; //return size

}

private static String[] setUserNames(int size) {

String userNames[]=new String[size]; //userNames array to store names

Scanner scan=new Scanner(System.in);

for(int i=0;i

System.out.printf("Enter a name for user "+(i+1)+":"); //Ask user to enter name

String name=scan.nextLine();

userNames[i]=name; //Store that name in userNames array at index i

}

return userNames; //Return userNames array

}

private static int[] setUserIDs(String userNames[]) {

int size=userNames.length;

int userIDs[]=new int[size]; //userIDs array to store ids of user

Scanner scan=new Scanner(System.in);

for(int i=0;i

System.out.printf("Enter user ID for "+userNames[i]+"?"); //Ask user to enter id for a name

int id=scan.nextInt();

userIDs[i]=id; //Store that id in userIDs array at index i

}

return userIDs; //return userIDs array

}

private static void printUserInfo(int[] userIDs,String userNames[]) {

System.out.printf("USER IDs & NAMES%n"); //Print header

//Iterate loop till size of the array and print user details

for(int i=0;i

System.out.printf("%s %d%n","User ID:",userIDs[i]);

System.out.printf("%s %s%n%n","User Name:",userNames[i]);

}

}

}//END class

{ int size=arraySize(); //Get array size String userNames[]=setUserNames(size); //Input userNames //PrintUserInfo by

Lab Exercise 7.1 Instructions: Name your program as YourLastNameFirstlnitialLE71.java. From the code in LE 6.2, do the following 1. You will NOT be changing any of the logic in the code for LE 6.2 2. Create a separate class called Users. This class will have NO main() 3. Insert a default constructor in the Users class. This is a method that is empty and its header looks like this: public NameOfClass() 4. Except, for the main), take all the other methods in LE 6.2 and put them in the Users class 5. Transfer the fields (class-level variables) from LE 6.2 to Users 6. Strip the word static from the fields and the method headers in the Users class 7. Cut and paste the main) from LE 6.2 into your program file for LE 7.1 1. Create an object of the Users class 1. Format NameOfClass objectName = new NameOfClass() 2. Use that object for the method calls in the main 1. Format: objectName.methodName0) 8. Make sure both classes are in the same directory 9. To run both programs, you must run the class with the main)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!