Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We are using Eclipse 2.0 Neon for coding (not sure if that makes a difference fo

ID: 3807210 • Letter: W

Question

We are using Eclipse 2.0 Neon for coding (not sure if that makes a difference for you).

( PB 09) Create a demo program for the agent class you created in PB06. The demo program will create an array of “agent” class type. You will prompt the user for the number of agents to be added. You will prompt the user for the information for each agent and display all the agent information after it has been entered. You will be using an array of agent class type to store the information the user enters.

(PB 06 for Reference)Modify or write a similar class to Ch6-PC4 so it holds data of an agent. The class should have two constructors, appropriate get and set methods and the following fields: agentID: see PC2-Ch7 agentName: String, the name of the agent payRate: see PC2-Ch7 hireDate: The date the agent was hired. agentType: The type of vehicles the agent sales (retail/commercial) commissionRate: The percentage of the sale that goes to the agent.

This was the completed PB 06 Program...

import java.util.Scanner;

/**Modify or write a similar class to Ch6-PC4 so it holds data of an agent. The class should

have two constructors, appropriate get and set methods and the following fields:

~ agentID: see PC2-Ch7

~ agentName: String, the name of the agent

~ payRate: see PC2-Ch7

~ hireDate: The date the agent was hired.

~agentType: The type of vehicles the agent sales (retail/commercial)

~commissionRate: The percentage of the sale that goes to the agent

*

*

* @author Melanie Walton

* @version 3-1-17

*/

public class Agent

{

   // instance variable

private int agentID;

   private String agentName;

   private double payRate;

   private String hireDate;

   private String agentType;

   private double commissionRate;

// constructors

   public Agent() {

       agentID = 0;

       agentName = "";

       payRate= 0;

       hireDate = "";

       agentType = "retail";

       commissionRate = 0;

   }

   public Agent(int agentID, String agentName, double payRate, String hireDate, String agentType,

double commissionRate) {

this.agentID = agentID;

       this.agentName = agentName;

       this.payRate = payRate;

       this.hireDate = hireDate;

       this.agentType = agentType;

       this.commissionRate = commissionRate;

   }

   // getters and setters

public int getAgentID() {

       return agentID;

   }

public String getAgentName() {

       return agentName;

}

   public double getPayRate() {

       return payRate;

}

   public String getHireDate() {

       return hireDate;

}

public String getAgentType() {

       return agentType;

}

   public double getCommissionRate() {

       return commissionRate;

   }

   public void setAgentID(int agentID) {

       this.agentID = agentID;

}

public void setAgentName(String agentName) {

       this.agentName = agentName;

}

   public void setPayRate(double payRate) {

       this.payRate = payRate;

}

   public void setHireDate(String hireDate) {

       this.hireDate = hireDate;

}

public void setAgentType(String agentType) {

       this.agentType = agentType;

}

   public void setCommissionRate(double commissionRate) {

       this.commissionRate = commissionRate;

}

}

Here is what I have so far for PB 09...

public class Month {

// declares class fields

      private int monthNum;

      /**

      * This constructor sets the monthNum to 1

      */

private Month()

      {

monthNum=1;

      }//end of Month

      /**

      * This constructor accepts an integer from the user.If the number is not between

      * 1-12 it sets the month

      *number to 1.

      *

      *

      * @param m The integer sent by the user

      */

      private void Month(int m)

      {

            if (m < 1 && m > 12)

                  monthNum=1;

            else

                  monthNum=m;

      }//end of void Month

      /**

      * This constructor will take string input and

      * set the month number based on the string input sent

      *

      * @param m

      */

      private month(String m)

      {

            //setting a case...set it like above-to 1 by default

      }

}end of whole class

Explanation / Answer

Note: Tested on Ubuntu

/******************************Agent.java*******************************/

/**
*
* @author Lalchand Mali
*/
public class Agent {
    // instance variable

    private int agentID;

    private String agentName;

    private double payRate;

    private String hireDate;

    private String agentType;

    private double commissionRate;

    // constructors
    public Agent() {

        agentID = 0;

        agentName = "";

        payRate = 0;

        hireDate = "";

        agentType = "retail";

        commissionRate = 0;

    }

    public Agent(int agentID, String agentName, double payRate, String hireDate, String agentType,
            double commissionRate) {

        this.agentID = agentID;

        this.agentName = agentName;

        this.payRate = payRate;

        this.hireDate = hireDate;

        this.agentType = agentType;

        this.commissionRate = commissionRate;

    }

    // getters and setters
    public int getAgentID() {

        return agentID;

    }

    public String getAgentName() {

        return agentName;

    }

    public double getPayRate() {

        return payRate;

    }

    public String getHireDate() {

        return hireDate;

    }

    public String getAgentType() {

        return agentType;

    }

    public double getCommissionRate() {

        return commissionRate;

    }

    public void setAgentID(int agentID) {

        this.agentID = agentID;

    }

    public void setAgentName(String agentName) {

        this.agentName = agentName;

    }

    public void setPayRate(double payRate) {

        this.payRate = payRate;

    }

    public void setHireDate(String hireDate) {

        this.hireDate = hireDate;

    }

    public void setAgentType(String agentType) {

        this.agentType = agentType;

    }

    public void setCommissionRate(double commissionRate) {

        this.commissionRate = commissionRate;

    }
}

/***************************AgentTest.java*************************/

import java.util.Scanner;

/**
*
* @author Lalchand
*/
public class AgentTest {

    public void printAgentData(Agent[] agents) {
        /**
         * Printing Agent data.
         */
        System.out.println("+++++++++++++++++Agent Data+++++++++++++++++++++++++");
        for (int i = 0; i < agents.length; i++) {
            System.out.println("AgentId: " + agents[i].getAgentID() + " AgentName: " + agents[i].getAgentName()
                    + " PayRate: " + agents[i].getPayRate() + " HireDate: " + agents[i].getHireDate() + " AgentType: " + agents[i].getAgentType()
                    + " commissionRate: " + agents[i].getCommissionRate());
        }
    }

    public static void main(String[] args) {
        AgentTest agentTest = new AgentTest();
        Scanner input = new Scanner(System.in);
        /**
         * Prompt for user input.
         */
        System.out.println("Please Enter number of agents to be added");
        int n = input.nextInt();
        input.nextLine();
        /**
         * creating array of Agent object.
         */
        Agent[] agents = new Agent[n];
        /**
         * prompt for agent information.
         */
        for (int i = 0; i < agents.length; i++) {
            agents[i] = new Agent();
            System.out.println("Please Enter agentId");
            agents[i].setAgentID(input.nextInt());
            input.nextLine();
            System.out.println("Please Enter agentName");
            agents[i].setAgentName(input.nextLine());
            System.out.println("Please Enter PayRate");
            agents[i].setPayRate(input.nextDouble());
            input.nextLine();
            System.out.println("Please Enter hireDate");
            agents[i].setHireDate(input.nextLine());
            System.out.println("Please Enter AgentType");
            agents[i].setAgentType(input.nextLine());
            System.out.println("Please Enter commissionRate");
            agents[i].setCommissionRate(input.nextDouble());
            input.nextLine();
        }
        /**
         * calling printAgentData method.
         */
        agentTest.printAgentData(agents);
    }
}


/*************************output****************************/

lalchand@lalchand:~/Desktop/Chegg-java$ javac AgentTest.java
lalchand@lalchand:~/Desktop/Chegg-java$ java AgentTest
Please Enter number of agents to be added
2
Please Enter agentId
1234
Please Enter agentName
Lalchand Mali
Please Enter PayRate
234
Please Enter hireDate
01-02-2017
Please Enter AgentType
retail
Please Enter commissionRate
12
Please Enter agentId
1235
Please Enter agentName
Sunita Saini
Please Enter PayRate
256
Please Enter hireDate
01-02-2017
Please Enter AgentType
commercial
Please Enter commissionRate
15
+++++++++++++++++Agent Data+++++++++++++++++++++++++
AgentId: 1234 AgentName: Lalchand Mali PayRate: 234.0 HireDate: 01-02-2017 AgentType: retail commissionRate: 12.0
AgentId: 1235 AgentName: Sunita Saini PayRate: 256.0 HireDate: 01-02-2017 AgentType: commercial commissionRate: 15.0


Thanks a lot

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote