
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
discuss how the scanner class, array, and for loop works in this code.
![import java.util.Scanner; // import Scanner class required to accept input from user
class Employee// To declare 3 variables for employee ID, Name and Salary
{
int ID;
String Name;
double Sal;
public void show (int i)
{
System.out.println("S1 No:
+ (i+1) + ",
+ Name + ", Salary:
Sal);
ID:
+ ID + ", Name:
public class Main
{
public static void main(String[] args)
{
int i;
int num;
Scanner obj = new Scanner(System.in);
System.out.print("Enter number of employees: "); // user should enter the number of employees
num = obj.nextInt();
System.out.println();
Employee emp[] = new Employee[num]; // create an array of num
for (i = 0; i < num; i++)
int ID;
String Name;
double Sal;
emp[i] = new Employee();
); // To store the employees details
System.out.println("Employee details "+ (i+1) +
System.out.print("
emp[i].ID = obj.nextInt();
obj.nextline();
System.out.print ("
emp[i].Name = obj.nextline();
System.out.print("
emp[i].Sal = obj.nextDouble();
Enter ID: ");
Enter Name: ");
Enter Salary: ");
}
System.out.println();
System.out.println("Employees details: "); // To display the employees details
for (i = 0; i < num; i++)
{
emp[i].show(i);
}
}](https://content.bartleby.com/qna-images/question/0453f204-f9ae-4ef7-86ca-355b1874dcff/e488293c-9a4c-4684-96b8-aa81a6854094/qu87b4f_thumbnail.png)
Transcribed Image Text:import java.util.Scanner; // import Scanner class required to accept input from user
class Employee// To declare 3 variables for employee ID, Name and Salary
{
int ID;
String Name;
double Sal;
public void show (int i)
{
System.out.println("S1 No:
+ (i+1) + ",
+ Name + ", Salary:
Sal);
ID:
+ ID + ", Name:
public class Main
{
public static void main(String[] args)
{
int i;
int num;
Scanner obj = new Scanner(System.in);
System.out.print("Enter number of employees: "); // user should enter the number of employees
num = obj.nextInt();
System.out.println();
Employee emp[] = new Employee[num]; // create an array of num
for (i = 0; i < num; i++)
int ID;
String Name;
double Sal;
emp[i] = new Employee();
); // To store the employees details
System.out.println("Employee details "+ (i+1) +
System.out.print("
emp[i].ID = obj.nextInt();
obj.nextline();
System.out.print ("
emp[i].Name = obj.nextline();
System.out.print("
emp[i].Sal = obj.nextDouble();
Enter ID: ");
Enter Name: ");
Enter Salary: ");
}
System.out.println();
System.out.println("Employees details: "); // To display the employees details
for (i = 0; i < num; i++)
{
emp[i].show(i);
}
}

Transcribed Image Text:---JGRASP exec: java Main
Enter number of employees: 2
Employee details 1:
Enter ID: 1120
Enter Name: Sara
Enter Salary: 800
Employee details 2:
Enter ID: 1234
Enter Name: Asma
Enter Salary: 900
Employees details:
s1 No: 1, ID: 1120, Name: Sara, Salary: 800.0
S1 No: 2, ID: 1234, Name: Asma, Salary: 900.0
---JGRASP: operation complete.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

Knowledge Booster
Similar questions
- (with Java please)arrow_forwardyou will write a c++ program to input 5 elements (of type int) from the user and store them in an array. Your program should then reverse the array and display it. For instance, if the user enters 1 2 3 4 5 as the five elements of the array, your program should reverse it and display: 5 4 3 2 1 Note: You must use a for loop to process the array.arrow_forwardTo what is the term “base address of an array” refer, and how is it used in a function call?arrow_forward
- (Flattening arrays with flatten vs. ravel) Create a 2-by-3 array containing the first six powers of 2 beginning with 2^0. Flatten the array first with method flatten, then with ravel. In each case, display the result then display the original array to show that it was unmodified. Please use Python and keep it simple.arrow_forwardIdentify the difference between STACK and ARRAY.arrow_forwardIn Between Code in C languagearrow_forward
- C++ ONLY PLEASE, and please read carefully, i have had people submit wrong answers Assignment 7 A: Rare Collection. We can make arrays of custom objects just like we’ve done with ints and strings. While it’s possible to make both 1D and 2D arrays of objects (and more), for this assignment we’ll start you out with just one dimensional arrays. Your parents have asked you to develop a program to help them organize the collection of rare CDs they currently have sitting in their car’s glove box. To do this, you will first create an AudioCD class. It should have the following private attributes. String cdTitle String[4] artists int releaseYear String genre float condition Your class should also have the following methods: Default Constructor: Initializes the five attributes to the following default values: ◦ cdTitle = “” ◦ artists = {“”, “”, “”, “”} ◦ releaseYear = 1980 ◦ genre = “” ◦ condition = 0.0 Overloaded Constructor: Initializes the five attributes based on values passed…arrow_forwardI want to know how to write this C++ code with comments to help me understand better.arrow_forwardPlease use easy logic with proper indentations and comments for understanding!. Coding should be in C++. 3. Define a class which stores up to 10 integer values in an array. The class should also define the following 4 public methods: setNumber – accepts an integer value to store in the array. The value is stored in the next available element of the array (first call to the method stores the value in element 0 with the second call storing the value in element 1.) The method returns true if there is room in the array and the integer was successfully stored. Returns false otherwise. clear – removes all values from the array so that the array can be reused. displayNumbers – displays the values currently stored in the array. getStats – determines the largest, smallest, and average of the values currently stored in the array. These values are returned to the caller via reference parameters. All methods should produce correct results regardless of the order in which…arrow_forward
- We'll talk about writing array notation in this part.arrow_forwardQUESTION 1 When defining a Java array, the index range of the array: Must start at 1 Must start at 0 Can be a customized range (from 2 to 5, e.g.) at compilation time Can be a customized range (from 2 to 5, e.g.) at run timearrow_forwardCan you please help me write the code in C++? It needs to be exactly wrote like the example in black. Also, if you can include a random number generator between [1,9] for the Matrixes then, that would be great. Note: Use DO-WHILE loop to verify user input for scale factor.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY