JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
9th Edition
ISBN: 9780357616673
Author: FARRELL
Publisher: CENGAGE L
Expert Solution & Answer
Book Icon
Chapter 9, Problem 4PE

Explanation of Solution

Program:

File name: “Salesperson.java

//Define a class named Salesperson

public class Salesperson

{

    //Declare the private variables

    private int id;

    private double sales;

    /*Define a method named Salesperson

    that takes two arguments*/

    Salesperson(int idNum, double amt)

    {

        //Assign the values

        id = idNum;

        sales = amt;

    }

    //Define a get method that returns the ID number

    public int getId()

    {

        //Return the value

        return id;

    }

    //Define a get method that returns the sales value

    public double getSales()

    {

        //Return the value

        return sales;

    }

    //Define a set method that takes the ID number

    public void setId(int idNum)

    {

        //Assign the value

        id = idNum;

    }

    //Define a set method that takes the sales value

    public void setSales(double amt)

    {

        //Assign the value

        sales = amt;

    }

}

File name: “SalespersonSort.java

//Import necessary header files

import javax.swing.*;

//Define a class named SalespersonSort

public class SalespersonSort

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare an array to store seven Salesperson objects

        Salesperson[] salespeople = new Salesperson[7];

        //Declare the variables

        int x;

        int id;

        double sales;

        String order;

        String message = "";

        //For loop to be executed until x exceeds 7

        for(x = 0; x < salespeople.length; ++x)

        {

            //Prompt the user to enter an ID number

id = Integer.parseInt(JOptionPane.showInputDialog(null,

            "Enter an ID number"));

            //Prompt the user to enter the sales value

sales = Double.parseDouble(JOptionPane.showInputDialog(null,

            "Enter sales value"));

            salespeople[x] = new Salesperson(id, sales);

        }

        /*Prompt the user to enter the choice of displaying

the objects in order by either ID number or sales value*/

        order = JOptionPane.showInputDialog(null,

         "By which field do you want to sort?\n" +

         "(I)d number or (S)ales");

        //If the user enters the choice, ID number

        if(order.charAt(0) == 'I')

            //Function call

            sortById(salespeople);

        //Else the user enters the choice, sales value

        else

            //Function call

            sortBySales(salespeople);

        //For loop to be executed until x exceeds 7

        for(x = 0; x < salespeople...

Blurred answer
Students have asked these similar questions
Of the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.
Management Information Systems
Q2/find the transfer function C/R for the system shown in the figure Re ད
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,