Results 1 to 3 of 3
  1. #1
    ERICAMAUVE4 is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Exclamation Need Help in BlueJ... Cannot figure this out.

    I am trying to do object interaction...

    Here's the code for the Sales Person..



    public class SalesPerson
    {
    private String name;
    private int employeeId;
    public double commissionRate;
    public double sales;

    /**
    * Constructor for objects of class Sales Person.
    */
    public SalesPerson (String salesPersonName, int salesPersonEmployeeId, double salesPersonCommissionRate, double salesPersonSales)
    {
    this.name = salesPersonName;
    this.employeeId = salesPersonEmployeeId;
    this.commissionRate = salesPersonCommissionRate;
    this.sales = salesPersonSales;
    }

    /**
    * To set the sales amount, enter the amount of sales you want to double.
    */
    public void setSalesAmount(double amount)
    {
    // This will set the sales amount.
    sales = amount;
    }

    /**
    * To set the commission rate for the sales person.
    */
    public void setCommissionRate(double rate)
    {
    // This will set the sales commission rate.
    if(rate <= 15) {
    commissionRate = rate;
    }
    else {
    System.out.println("You must enter a rate from 0% to 15%.");
    }
    }

    /**
    * Calculates the commission rate times the sales amount.
    */
    public double calcCommission()
    {
    if(sales >= 10001) {
    return commissionRate = ((commissionRate * 2) * sales);
    }
    else {
    return commissionRate = (commissionRate * sales);
    }
    }

    /**
    * Prints the Sale's person's name, ID, the sales amount, and the calculated commision amount.
    */
    public void print()
    {
    //This will print all the information on the Sale's Person.
    System.out.println( "Sales Person's Name: " + name);
    System.out.println( "Sales Person's ID: " + employeeId);
    System.out.println( "Sales Person's Sales Amount: " + sales);
    System.out.println( "Sales Person's Commission Amount: " + commissionRate);
    }
    }


    And then here's for the manager...

    public class Manager
    {
    private String name;
    private int employeeId;
    private SalesPerson salesPerson;

    /**
    * Constructor for objects of class Manager
    */
    public Manager(String managerName, int managerEmployeeId)
    {
    this.name = managerName;
    this.employeeId = managerEmployeeId;
    this.salesPerson = new SalesPerson("Erica");
    }

    /**
    * Enter a commission rate for the Sales Person.
    */
    public SalesPerson setCommissionRate(double newRate)
    {
    // Sets the commission rate for the Sales Person.
    salesPerson = new commissionRate();
    }

    }


    I cannot compile. It keeps saying that there is an error (cannot find symbol- constructor SalesPerson(java.lang.String) when I get to the bolded " this.salesPerson = new SalesPerson("Erica");".

    Please help, I've been trying to figure this out for 3 days! :(

  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    You have not created a constructor which only takes one java.lang.String as an argument.

    Your SalesPerson contructor takes a String, int, double, double.

    Your calling a constructor which you have not defined.

  3. #3
    pkang is offline Member
    Join Date
    Sep 2009
    Posts
    6
    Rep Power
    0

    Thumbs up

    Try with the following modify code:
    1- provide new constructor to
    Java Code:
    [COLOR="red"]public SalesPerson(String salePersonName) {
    	this.name = salePersonName;
    }[/COLOR]
    2- update your Manger and the way you call "setCommision"

    Java Code:
    public class Manager
    {
    	private String name;
    	private int employeeId;
    	private SalesPerson salesPerson;
    
    	/**
    	 * Constructor for objects of class Manager
    	 */
    	public Manager(String managerName, int managerEmployeeId)
    	{
    		this.name = managerName;
    		this.employeeId = managerEmployeeId;
    		this.salesPerson = new SalesPerson("Erica");
    	}
    
    	/**
    	 * Enter a commission rate for the Sales Person.
    	 */
    	public [COLOR="Red"]void [/COLOR]setCommissionRate(double newRate)
    	{
    		// Sets the commission rate for the Sales Person.
    		[COLOR="Red"]salesPerson.setCommissionRate(newRate);[/COLOR]	}
    
    }

Similar Threads

  1. BlueJ help
    By Cid17 in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 08:38 PM
  2. Java Applet Help with BlueJ
    By moofs in forum New To Java
    Replies: 0
    Last Post: 01-15-2009, 05:24 AM
  3. Replies: 1
    Last Post: 04-17-2008, 03:30 PM
  4. help using BlueJ
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:07 AM
  5. BlueJ 2.2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-07-2007, 03:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •