1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
fgiga [73]
2 years ago
15

In Chapter 8, Programming Exercise 6 you created a Salesperson class with fields for an ID number and sales values. Now, create

an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in ascending order by either (I)D number or (S)ales value.
An example of the program is shown below:

Enter an ID number
100
Enter sales value
250
Enter an ID number
101
Enter sales value
500.25
Enter an ID number
103
Enter sales value
600.50
Enter an ID number
106
Enter sales value
78
Enter an ID number
105
Enter sales value
80.2
Enter an ID number
102
Enter sales value
45.68
Enter an ID number
104
Enter sales value
120
By which field do you want to sort?
(I)d number or (S)ales
I

ID 100 sales: 250.0
ID 101 sales: 500.25
ID 102 sales: 45.68
ID 103 sales: 600.5
ID 104 sales: 120.0
ID 105 sales: 80.2
ID 106 sales: 78.0
Computers and Technology
1 answer:
sattari [20]2 years ago
5 0

Using the knowldge in computional language in Java it is possible to write a code that create an application that allows a user to enter values for an array of seven Salesperson objects.

<h3>Writing the code in Java</h3>

import java.util.*;

public class Salesperson

{

private int ID;

private double annualSales;

public Salesperson(int ID, double annualSales)

{

this.ID = ID;

this.annualSales = annualSales;

}

public int getID()

{

return ID;

}

public void setID(int ID)

{

this.ID = ID;

}

public double getAnnualSales()

{

return annualSales;

}

public void setAnnualSales(double annualSales)

{

this.annualSales = annualSales;

}

public String toString()

{

return "Salesperson ID: " + ID + ", annual sales: " + annualSales;

}

}

// you created a Salesperson class with fields for an ID number and sales values. Now,

// create an application that allows a user to enter values for an array of seven Salesperson objects.

// Offer the user the choice of displaying the objects in order by either ID number or sales value.

// Save the application as SalespersonSort.java

public class SalespersonSort

{

public static void main(String[] args)

{

Salesperson[] array = new Salesperson[7];

Scanner in = new Scanner(System.in);

for(int i=0; i<array.length; i++){

System.out.print("\nEnter ID number of Sales Person "+ (i+1) + " :");

int ID = in.nextInt();

System.out.print("\nEnter Annual Sales of Sales Person "+ (i+1) + " :");

double sales = in.nextDouble();

array[i] = new Salesperson(ID,sales);

}

System.out.println("Do you want to sort by ID or sales? (Enter ID or sales):");

String choice = in.next();

if(choice.equalsIgnoreCase("ID")){

for(int i=0; i<array.length; i++){

int min = i;

for(int j=i; j<array.length; j++){

if(array[j].getID() < array[min].getID())

min = j;

}

Salesperson temp = array[i];

array[i] = array[min];

array[min] = temp;

}

System.out.println("Sales sorted by ID are ");

for(int i=0; i<array.length; i++)

System.out.println(array[i]);

}

else{

for(int i=0; i<array.length; i++){

int min = i;

for(int j=i; j<array.length; j++){

if(array[j].getAnnualSales() < array[min].getAnnualSales())

min = j;

}

Salesperson temp = array[i];

array[i] = array[min];

array[min] = temp;

}

System.out.println("Sales sorted by Annual Sales are ");

for(int i=0; i<array.length; i++)

System.out.println(array[i]);

}

See more about Java at: brainly.com/question/12978370

#SPJ1

You might be interested in
What was used to enhance silent films of the early 1900s
alisha [4.7K]
Ask internet it will tell u
7 0
3 years ago
The ____ documents a system at the end of the design phase, identifies any changes since the beginning of the project, and inclu
nekit [7.7K]

Answer:

allocated baseline

Explanation:

The allocated baseline documents a system at the end of the design phase, identifies any changes since the beginning of the project, and includes testing and verification of all system requirements and features.

Hope this helps!

5 0
3 years ago
Read 2 more answers
What is the unit of measure ment to easure cpu speed
Hatshy [7]

Answer:

gigahertz (GHz )

Explanation:

A “cycle” is technically a pulse synchronized by an internal oscillator, but for our purposes, they're a basic unit that helps understand a CPU's speed

7 0
3 years ago
What do astronomers call a system that is composed of more than two stars?
Nezavi [6.7K]
Nazils system is the anwser
7 0
3 years ago
Read 2 more answers
Imaging a computer is part of what phase of conversion?
grandymaker [24]
B. Because the computer can rearrange itself when it is in a phase of conversion
5 0
3 years ago
Other questions:
  • Consider the following method intended to modify the parameter names by removing all instances of the String n.
    14·1 answer
  • By using colocated, replicated hardware and software, cloud solution providers reduce many threats to IT resources.
    5·1 answer
  • Alkane is a Variety of which fruit
    6·1 answer
  • The __________ of a desktop computer is the case that houses the computerâs critical parts, such as the processing and storage d
    5·1 answer
  • A file containing user information which is transmitted from an online server and attached to your web browser and stored on you
    11·1 answer
  • What type of interview would be most likely for the following scenario?
    11·2 answers
  • The chain of command is an unbroken line of authority that extends from the top of the organization to the lowest echelon and cl
    7·1 answer
  • What are the pros and cons of using the internet in a medical office setting?
    7·1 answer
  • Define E-Mail Write any 4 special features of E-Mail ​
    13·1 answer
  • Using complete sentences post a detailed response to the following.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!