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
If you were to create a new app for a smartphone or tablet that does not already exist, what would you create?
omeli [17]
A app that fry’s your Phone or Tablet.
4 0
3 years ago
Bukod sa nakasulat na impormasyon ay makakakita rin ng larawan sa internet.​
faltersainse [42]

i woud love to help but i dont understand the language

7 0
2 years ago
There are several categories of utility programs that were discussed in this unit. For this item, list one. In one to three sent
Zolol [24]

Answer:

Antivirus

Explanation:

The antivirus software is a utility program and what it basically does include: (1) detecting of virus on the computer system (2) bring to the notice of the computer user, the presence of virus on the system.

An example is Avast Antivirus.

6 0
3 years ago
When a computer is infected by a virus, _______.
ira [324]

Answer:

Explanation:

A virus can damage programs, delete files and reformat or erase your hard drive, which results in reduced performance or even crashing your system entirely. Hackers can also use viruses to access your personal information to steal or destroy your data.

8 0
3 years ago
You have just started an internship on a graphic design team and you are learning about graphic formats used on the web. Which o
Aneli [31]

Answer:

Portable Network Graphics is the correct answer of this question.

Explanation:

Portable Network Graphics i is the graphics formats which we use for comic-style drawing Portable Network Graphics is a media structure that is used to compress digital video objects. Portable Network Graphics almost completely overtaken the Graphics Merge Standard (GIF),which has been commonly used during the history.

<u>For example</u>:- Portable Network Graphics images use lossless compression      like GIF files.

  • It has an indexed color raster image and is optimized with a data compression comparable to a GIF file.
  • Portable Network Graphics files are widely used to store opaque background Web graphics, digital photographs and images.

6 0
3 years ago
Other questions:
  • What is the number 5280 in binary
    14·1 answer
  • Assume you have functions f and g such that f(n) is O(g(n)). For each of the following statements, decide whether you think it i
    12·1 answer
  • First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==&gt; Close All Projects).
    6·1 answer
  • ∑_(A,B,C,D,E)▒〖(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)〗
    8·1 answer
  • 2.1. The stream cipher described in Definition 2.1.1 can easily be generalized to work in alphabets other than the binary one. F
    10·1 answer
  • What does it mean to say RAM is volatile? *
    9·1 answer
  • What is the full form of ICT?​
    14·2 answers
  • How many fields can be sorted when sorting data in Word tables? up to 3 fields 1 field at a time up to 4 fields 2 fields at a ti
    7·2 answers
  • A museum is evaluating historical documents for authenticity, reviewing their physical condition, and categorizing them by subje
    9·1 answer
  • Relational operators compare values and determine whether a condition of an if statement is true or false.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!