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
Suppose you are using a jQuery animation to make an element change color when the user clicks on it, and you also want to execute a function as soon as the animation finishes running. How can you do this? a. Pass the function in as the first argument to theanimate()method called on the element. b. Use anif elseblock with thehasClass()method to determine when to call the function. c. Pass the function in as the final argument to theanimate()method called on the element. d. You cannot accomplish this using jQuery commands.
The developers of a free online game named Sugar Smash have asked you to develop a class named SugarSmashPlayer that holds data about a single player. The class contains the following fields: idNumber - the player’s ID number (of type int) name - the player's screen name (of type String) scores - an array of integers that stores the highest score achieved in each of 10 game levels Include get and set methods for each field. The get method for scores should require the game level to retrieve the score for. The set method for scoresshould require two parameters—one that represents the score achieved and one that represents the game level to be retrieved or assigned. Display an error message if the user attempts to assign or retrieve a score from a level that is out of range for the array of scores. Additionally, no level except the first one should be set unless the user has earned at least 100 points at each previous level. If a user tries to set a score for a level that is not yet…
This is the question I am stuck on - A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer argument and returns the CollegeCourse in that position (0 through 4). Next, create a set method that sets the value of one of the Student’s CollegeCourse objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4). B. Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for…
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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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