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
What is the missing line of code? &gt;&gt;&gt;from math th import &gt;&gt;&gt; Point = [1,5) &gt;&gt;&gt; bPoint [4.9]​
Ulleksa [173]

Answer:

I believe import math.

Do let me know if its correct.

3 0
2 years ago
Michelle is writing an assignment on programming language. Help Michelle complete the following statement that describes the inp
Oliga [24]

Input statements allow the user to enter data that a program uses to perform necessary computations. Users enter the data when they <u>encounter the statements like the scanf() or gets() functions in the program.</u>

<u>Explanation:</u>

The scanf() is the function that is used to take inputs from the user with the help of the standard input device,i.e, the keyboard.

scanf() function is capable of taking any data type as an input, though it has to be specified first like %d for integers, %s for strings and %f for floating-point type. The gets() function can only take a string as an input.

3 0
4 years ago
__________ ensure that hardware and software produced by different vendors work together.
inna [77]
Hi!

Standards are what help ensure that hardware and software made by different vendors can work together.

Hopefully, this helps! =)
4 0
3 years ago
When you perform an in-place upgrade to windows 8.1 from windows 7, what will be names of the “windows” folders in windows 7 and
juin [17]
THIS PC. 

HOPE THIS HELPS
3 0
4 years ago
Choose the correct completion: Services and APIs are enabled on a per-__________ basis.
Ghella [55]

Answer:

the answer to the fill-in is <em>project. </em>

Explanation:

4 0
3 years ago
Other questions:
  • There’s No Difference In Security If You Use A Public PC Or Your Own Computer.
    6·1 answer
  • The next thing Maia wants to do is to indent the first line of her paragraphs.
    15·2 answers
  • How many bits are required to write decimal number?
    9·1 answer
  • Users generally do not understand the concept of network drive sharing. they only know they can store their files "on my f: driv
    8·1 answer
  • A copy of the copyrighted work must be exactly the same as the original to infringe a copyright.
    9·1 answer
  • Monica wants insert a cover page for her report. She needs to be sure her insertion point is at the beginning of the report.
    7·1 answer
  • How does the actual amount left to spend differ from the budgeted amount for the remaining three months of the project?
    12·1 answer
  • How can you resize the program window?​
    5·2 answers
  • HELPPPPP Which tag used to add a new line:<br> A. ol<br> B. P<br> C. h1<br> D li
    7·1 answer
  • Evaluation, formatting, expanding/decoding, distillation/reduction, and assessment are examples of ________ computing operations
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!