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
Alex Ar [27]
3 years ago
10

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
This is the code for Salesperson class:
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;
}
}

Computers and Technology
1 answer:
Svetradugi [14.3K]3 years ago
7 0

Answer:

Following are the class "SalespersonSort" code to this question:

public class SalespersonSort //defining a class SalespersonSort

{

public static void main(String[] ax) //defining a main method  

{

int id;//defining integer variable

double sales; //defining double variable

String select;//defining String variable

Salesperson[] x = new Salesperson[7]; //crating array as the Salesperson class

Scanner x1= new Scanner(System.in);//creating scanner class object

for(int i=0; i<x.length; i++)//defining loop for input values

{

System.out.print("Enter ID number "+(i+1)+": ");//print message

id = x1.nextInt();//input value

System.out.print("Enter Annual Sales "+(i+1)+": ");//print message

sales = x1.nextDouble(); //input value

x[i]=new Salesperson(id,sales);//hold value in array x

}

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

select= x1.next();//input value

if(select.equalsIgnoreCase("ID"))//define if block that sort value by id

{

for(int i=0; i<x.length; i++)//define for loop to collect value

{

int m= i;//use integerv variable to hold i value

for(int j=i; j<x.length; j++)//define for loop to sort value

{

if(x[j].getID() < x[m].getID())//use if block for check value

m = j;//use integerv variable to hold j value

}

//perform swapping

Salesperson t = x[i];//define calss type variable t to hold aaray value

x[i] = x[m];//inter change value

x[m] = t;//store value in x

}

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

for(int i=0; i<x.length; i++)//define for loop to print sort value

System.out.println(x[i]);//print value

}

else//defining else block

{

for(int i=0; i<x.length; i++)//define for loop to collect value

{

int m= i;//use integerv variable to hold i value

for(int j=i; j<x.length; j++)//define for loop to sort value

{

if(x[j].getAnnualSales() < x[m].getAnnualSales())//sort value by sales

m = j;//hold j value in m

}

//perform swapping

Salesperson t = x[i];//define calss type variable t to hold aaray value

x[i] = x[m];//inter change value

x[m] = t;//store value in x

}

System.out.println(" sort value by Annual Sales: "); //print message

for(int i=0; i<x.length; i++)//defining for loop to print value

System.out.println(x[i]);//print value

}

}

}

output:

please find the attached file.

Explanation:

In the above-given code, a class "SalespersonSort" is defined, inside the class main method is defined, in the method three variables "sales, select, and id" is defined, that is datatype different.

In the class, Salesperson as an array is defined and a scanner class object created that inputs array values and in the string value and a conditional statement is used.

In the if block, it sort values according to id value, and in the else block it sort value according to sales value.  

please find the attachment of full code.

You might be interested in
Jill edited James's document using Track Changes. James agrees with all of the edits and wants to incorporate them into his text
jenyasd209 [6]
The quick way for James to do so would be : A. open the tools menu, select options, and then select the track changes

with this method, James doesn't have to accept the edits one at a time which will waste his time

hope this helps
4 0
4 years ago
3.4 code practice question 2 edhesive
Gelneren [198K]
???????????????????
7 0
3 years ago
Read 2 more answers
Terrance is looking for a storage device to be used for backup storage. The device has to have a large storage capacity and be p
alexdok [17]

Answer:

externral hard drive

Explanation:

my friend told me

6 0
3 years ago
Read 2 more answers
Which device acts as a gateway to allow hosts to send traffic to remote ip networks?
SashulF [63]
A router.

------------------------------------
4 0
3 years ago
Read 2 more answers
Can someone write this in java? Also, does anyone know how to do Edhesive assignments?
svetoff [14.1K]
No I don’t know what are you saying can you explain or I’m here for points heheheh and Java is written in any way
7 0
3 years ago
Other questions:
  • In the simulation, player 2 will always play according to the same strategy. The number of coins player 2 spends is based on wha
    6·1 answer
  • Josh needs to write a research report for his Civics class. Which file type will allow him to save his file?
    12·2 answers
  • Dr. Laos gets a referral for a 6 month old who has become listless and stopped eating lately. Her pediatrician wanted her to be
    15·1 answer
  • A broadcast network is one in which a transmission from any one attached station is received by all other attached stations over
    10·1 answer
  • Create a program to calculate the wage. Assume people are paid double time for hours over 60 a week. Therefore they get paid for
    10·1 answer
  • Why does world of tanks keep downloading when I'm not even at the computer
    9·1 answer
  • is defined as the condition in which all of the data in the database are consistent with the real-world events and conditions
    7·1 answer
  • Can someone help me find all the solutions to the problem ​
    5·2 answers
  • Pls help me Pls help me
    13·1 answer
  • How does the internet works
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!