Using Java Create a GUI to enter data for the Agent and Senior Agent classes. I
ID: 3833722 • Letter: U
Question
Using Java
Create a GUI to enter data for the Agent and Senior Agent classes. I am providing these 2 classes that I have already written and compiled with no syntax errors. Was needing to figure out how to add the "Bonus" and "Quota" button information specific to Senior Agent to have it only populate if they click on the senior agent radio button but if they click on the junior agent radio button then it will not populate for the user.
Agent Class
import java.util.Scanner;
import java.util.*;
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;
}
public static void main(String[] args)
{
//Creating arraylist because we don't know the number of agents to be added
ArrayList<Agent> list=new ArrayList<Agent>();
Scanner scan = new Scanner(System.in);
int n;
System.out.println("Enter number of agents to be added");
n = scan.nextInt();
int newID;
String newName;
double newPayRate;
String newHireDate;
String newAgentType;
double newCommissionRate;
for(int i=0;i<n;i++)
{
System.out.println("Enter details of agent " + (i+1));
// take input from user
System.out.println("Enter Agent ID :");
newID = scan.nextInt();
System.out.println("Enter Agent name :");
scan.nextLine(); //done because newInt doesn' take newline character as input
newName = scan.nextLine();
System.out.println("Enter Agent pay rate :");
newPayRate = scan.nextDouble();
System.out.println("Enter Agent hire date :");
scan.nextLine();
newHireDate = scan.nextLine();
System.out.println("Enter Agent type :");
newAgentType = scan.nextLine();
System.out.println("Enter Agent commission rate :");
newCommissionRate = scan.nextDouble();
Agent newAgent = new Agent(newID, newName, newPayRate, newHireDate, newAgentType, newCommissionRate);
list.add(newAgent);
}
for(int i=0;i<n;i++)
{
Agent temp = list.get(i);
System.out.println("Details of agent " + (i+1));
// print details of agent
System.out.println("Agent ID : " + temp.getAgentID());
System.out.println("Agent name : " + temp.getAgentName());
System.out.println("Agent pay rate : " + temp.getPayRate());
System.out.println("Agent hire date : " + temp.getHireDate());
System.out.println("Agent type : " + temp.getAgentType());
System.out.println("Agent commission rate : " + temp.getCommissionRate());
}
}
}
SeniorAgentClass
/**
* Write a description of class SeniorAgent here.
*
* @author Melanie Walton
* @version PB 12 4-20-17
*/
public class SeniorAgent extends Agent {
private double bonus;
private double quota;
public SeniorAgent() {
bonus = 0;
quota = 0;
}
public SeniorAgent(int agentID, String agentName, double payRate, String hireDate, String agentType,
double commissionRate, double bonus, double quota) {
super(agentID, agentName, payRate, hireDate, agentType, commissionRate);
this.bonus = bonus;
this.quota = quota;
}
public double getBonus() {
return bonus;
}
public double getQuota() {
return quota;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public void setQuota(double quota) {
this.quota = quota;
}
// Method to calculate bonus if it meets minimum criteria
public double bonusEarned(double sale){
if(quota <= sale)
return getPayRate()*bonus;
else
return 0;
}
}
Explanation / Answer
import java.util.Scanner;
import java.util.*;
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;
}
public static void main(String[] args)
{
//Creating arraylist because we don't know the number of agents to be added
ArrayList<Agent> list=new ArrayList<Agent>();
Scanner scan = new Scanner(System.in);
int n;
System.out.println("Enter number of agents to be added");
n = scan.nextInt();
int newID;
String newName;
double newPayRate;
String newHireDate;
String newAgentType;
double newCommissionRate;
for(int i=0;i<n;i++)
{
System.out.println("Enter details of agent " + (i+1));
// take input from user
System.out.println("Enter Agent ID :");
newID = scan.nextInt();
System.out.println("Enter Agent name :");
scan.nextLine(); //done because newInt doesn' take newline character as input
newName = scan.nextLine();
System.out.println("Enter Agent pay rate :");
newPayRate = scan.nextDouble();
System.out.println("Enter Agent hire date :");
scan.nextLine();
newHireDate = scan.nextLine();
System.out.println("Enter Agent type :");
newAgentType = scan.nextLine();
System.out.println("Enter Agent commission rate :");
newCommissionRate = scan.nextDouble();
Agent newAgent = new Agent(newID, newName, newPayRate, newHireDate, newAgentType, newCommissionRate);
list.add(newAgent);
}
for(int i=0;i<n;i++)
{
Agent temp = list.get(i);
System.out.println("Details of agent " + (i+1));
// print details of agent
System.out.println("Agent ID : " + temp.getAgentID());
System.out.println("Agent name : " + temp.getAgentName());
System.out.println("Agent pay rate : " + temp.getPayRate());
System.out.println("Agent hire date : " + temp.getHireDate());
System.out.println("Agent type : " + temp.getAgentType());
System.out.println("Agent commission rate : " + temp.getCommissionRate());
}
}
}
SeniorAgentClass
/**
* Write a description of class SeniorAgent here.
*
* @author Melanie Walton
* @version PB 12 4-20-17
*/
public class SeniorAgent extends Agent {
private double bonus;
private double quota;
public SeniorAgent() {
bonus = 0;
quota = 0;
}
public SeniorAgent(int agentID, String agentName, double payRate, String hireDate, String agentType,
double commissionRate, double bonus, double quota) {
super(agentID, agentName, payRate, hireDate, agentType, commissionRate);
this.bonus = bonus;
this.quota = quota;
}
public double getBonus() {
return bonus;
}
public double getQuota() {
return quota;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public void setQuota(double quota) {
this.quota = quota;
}
// Method to calculate bonus if it meets minimum criteria
public double bonusEarned(double sale){
if(quota <= sale)
return getPayRate()*bonus;
else
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.