Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Initialising objects

Options
  • 29-11-2014 4:53pm
    #1
    Registered Users Posts: 945 ✭✭✭


    Hi all, wonder if you could help me with this?

    I'm trying to compile this:
    public class SortSoftwareProject
    {
    public static void main(String[] args)
    {
    SoftwareProject[] aProject = new SoftwareProject[6];
    aProject[0] = new SoftwareProject("IBM", 'D', 'M');
    aProject[1] = new SoftwareProject("Microsoft", 'C', 'M');
    aProject[2] = new SoftwareProject("Apple", 'Q', 'L');
    aProject[3] = new SoftwareProject("Intel", 'C', 'L');
    aProject[4] = new SoftwareProject("Me", 'S', 'D');
    aProject[5] = new SoftwareProject("You", 'M', 'Q');
    bubbleSort(aProject);
    for(int i = 0; i < aProject.length; i++)
    System.out.print(aProject.getCustomerName());
    }

    And this is the class I created.
    public class SoftwareProject
    {
    private String custName;
    private char projName;
    private char serType;
    private double projCost = 10000;


    public void SoftwareProject(String inputName, char inputProjectName, char serviceTypeName)
    {
    custName = inputName;
    projName = inputProjectName;
    serType = serviceTypeName;
    }

    public char getProjectName()
    {
    return projName;
    }

    public char getServiceType()
    {
    return serType;
    }

    public String getCustomerName()
    {
    return custName;
    }

    public double getProjectCost()
    {
    return projCost;
    }
    }

    Basicly, creating an array of projects to be bubble sorted by customer name.

    I have the method for the bubble sort, but I'm getting this compilation error:
    required: no arguments
    found: String,char,char
    reason: actual and formal argument lists differ in length
    SortSoftwareProject.java:11: error: constructor SoftwareProject in class Softwar
    eProject cannot be applied to given types;
    aProject[5] = new SoftwareProject("You", 'M', 'Q');
    ^
    required: no arguments
    found: String,char,char
    reason: actual and formal argument lists differ in length
    SortSoftwareProject.java:22: error: constructor SoftwareProject in class Softwar
    eProject cannot be applied to given types;
    temp = new SoftwareProject("word", 'a', 'b');
    ^

    Anyone spot what I'm doing wrong?


Comments

  • Registered Users Posts: 4,766 ✭✭✭cython


    CaoimH_in wrote: »
    Hi all, wonder if you could help me with this?

    I'm trying to compile this:



    And this is the class I created.



    Basicly, creating an array of projects to be bubble sorted by customer name.

    I have the method for the bubble sort, but I'm getting this compilation error:



    Anyone spot what I'm doing wrong?

    Constructors should not have a return type, i.e. within the SoftwareProject class
    public void SoftwareProject(String inputName, char inputProjectName, char serviceTypeName)
    {
    custName = inputName;
    projName = inputProjectName;
    serType = serviceTypeName;
    }
    

    should read
    public SoftwareProject(String inputName, char inputProjectName, char serviceTypeName)
    {
    custName = inputName;
    projName = inputProjectName;
    serType = serviceTypeName;
    }
    

    Because of the return type, you only actually have a default constructor with no arguments available, and as the error says, this can't be applied to an argument list.


  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,240 Mod ✭✭✭✭L.Jenkins


    public class SortSoftwareProject
    {
    public static void main(String[] args)
    {
    SoftwareProject aProject = new SoftwareProject();
    aProject = new SoftwareProject("IBM", 'D', 'M');
    aProject = new SoftwareProject("Microsoft", 'C', 'M');
    aProject = new SoftwareProject("Apple", 'Q', 'L');
    aProject = new SoftwareProject("Intel", 'C', 'L');
    aProject = new SoftwareProject("Me", 'S', 'D');
    aProject = new SoftwareProject("You", 'M', 'Q');
    bubbleSort(aProject);
    for(int i = 0; i < aProject.length; i++)
    System.out.print(aProject.getCustomerName());
    }
    .


  • Registered Users Posts: 4,766 ✭✭✭cython


    Itzy wrote: »
    .

    Are you trying to sort a single variable? Don't think that was what the OP was looking for..... You might as well rewrite yours as the below:
    public class SortSoftwareProject
    {
    public static void main(String[] args)
    {
    SoftwareProject aProject = new SoftwareProject();
    aProject = new SoftwareProject("You", 'M', 'Q');
    bubbleSort(aProject);
    for(int i = 0; i < aProject.length; i++)
    System.out.print(aProject[i].getCustomerName());
    }
    

    And I still think you'll get the same compile error for the reason I posted above


Advertisement