EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
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
Design an application (submit pseudocode) that declares an array of 12 BaseBallGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or "Tie" if the score is a tie.
Create a class name Taxpayer. Data fields for Taxpayer include yearly gross income and Social Security number (use an int for the type, and do not use dashes within the Social Security number). Methods include a constructor that requires a value for both data fields and two methods that each return one of the data field values. Write an application named USeTaxpayer that declares an array of 10 Taxpayer objects. Set each Social Security number to 999999999 and each gross income to zero. Display the 10 Taxpayer objects. Save the files as TAxpayer.java and USeTAxpayer.java
Design a class named BaseBallGame that has the fields for two names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. Design an application (submit pseudocode) that declares three BaseBallGame objects and sets and displays their values. Design an application (submit pseudocode) that declares an array of 12 BaseBallGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or "Tie" if the score is a tie.
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