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]
1 year 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]1 year 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 cell address indicates the intersection of the first row and the first column in a worksheet?
Roman55 [17]
The answer is A1. 

The columns are arranged alphabetically, and the rows are ordered numerically. The cell address states the column, a letter, followed by the row, a number. The first cell address, the top-left cell of the sheet, is A1
7 0
2 years ago
Read 2 more answers
i was playing a mobile game and I was a guild leader in there. one of the members were very disrespectful and they just left bec
Sonbull [250]

Answer:

which mobile game? Whatever the worst thing you can do is. If its slurs and harassment or bullying report them

Explanation:

3 0
2 years ago
Read 2 more answers
Abrupt changes in road surface or the shape of the road may indicate
Zanzabum

Answer:

D. a potential hazard

Explanation:

Abrupt changes in road surface or the shape of the road may indicate a potential hazard.

5 0
3 years ago
Read 2 more answers
The Sales team uses the /sales directory to store documents related to sales, contacts, and orders. Currently, permissions on th
kvasek [131]

Answer:

it should be d

Explanation:

please mark this as brainlists i could really use it

6 0
3 years ago
The critical path in a project network is:______ A. The Shortest path through the network. B. Longest path through the network.
Softa [21]

Answer:

B

Explanation:

4 0
3 years ago
Other questions:
  • An author is preparing to send their book to a publisher as an email attachment. The file on their computer is 1000 bytes. When
    6·1 answer
  • Which of the following statements about Java Class Libraries is false: a. Java class libraries consist of classes that consist o
    9·1 answer
  • So I’m doing a PowerPoint of how social media changed my life any ideas what I should right down and what kind of topics should
    11·2 answers
  • PLEASE  HELPPPP!!!!!
    14·1 answer
  • Adam is evaluating the security of a web server before it goes live. He believes that an issue in the code allows an SQL injecti
    5·1 answer
  • For a line segment, show that clipping against the top of the clipping rectangle can be done independently of the clipping again
    7·1 answer
  • The results of the SPEC CPU2006 bzip2 benchmark running on an AMD Barcelona has an instruction count of 2.389E12, an execution t
    6·1 answer
  • The rules on the Internet for how messages are addressed and passed on are called ____ .
    15·1 answer
  • Term of The surroundings and conditions of your workplace
    6·1 answer
  • What does the coding phase involve?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!