Question

In: Computer Science

Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...

Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects.

public class DemoSalesperson
{
public static void main (String args[])
{
// your code here
}
}
----------------------------------------------------------------------------------------------------------------------------------------------

public class Salesperson
{

// constructor

// get and set methods
  
}


Solutions

Expert Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package demosalesperson;
import java.util.*;
/**
*
* @author Addy
*/
class Salesperson{
private int id;
private double annualSalesAmount;
//constructor
public Salesperson(int ID, double annualSalary) {
id=ID;
annualSalesAmount=annualSalary;
}
//setter
public void setID(int i){
id=i;
}
public void setSalesAmount(double sal){
annualSalesAmount=sal;
}
//getter
public int getID(){
return id;
}
public double getSalesAmount(){
return annualSalesAmount;
}
  
  
}
public class DemoSalesperson {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
   Salesperson[] salePerson = new Salesperson[10]; //array pf objects
       for(int i = 0; i < 10; i++){
           salePerson[i] = new Salesperson(9999, 0); //setting
       }
       for(int i = 0; i < 10; i++){
//display
       System.out.println("ID: "+ salePerson[i].getID() + " Sales Amount: " + salePerson[i].getSalesAmount());
       }
}
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP


Related Solutions

Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales values. Now, 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 (I)D number or (S)ales value. ----------------------- Salesperson.java public class Salesperson {    private int id;    private double sales;    Salesperson(int idNum, double amt)    {       id = idNum;       sales = amt;    }    public int getId()...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
Create a class named Blanket with fields for a blanket’s size, color, material, and price. Include...
Create a class named Blanket with fields for a blanket’s size, color, material, and price. Include a constructor that sets default values for the fields as Twin, white, cotton, and $30.00. Include a set method for each of the first three fields. The method that sets size adds $10 to the base price for a double blanket, $25 for a queen blanket, and $40 for a king. The method that sets the material adds $20 to the price for wool...
Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT