Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Initialising objects

  • 29-11-2014 03:53PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 4,846 ✭✭✭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,242 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, Registered Users 2 Posts: 4,846 ✭✭✭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