Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: errror constructor class cannot be applied to give types

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default errror constructor class cannot be applied to give types

    I'm getting an error on line 51 and don't know what it means can someone help me fix this error ?
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package million;
    import java.util.Scanner;
    import java.util.ArrayList;
     
     
     
    /**
     *
     * @author Ernie
     */
    public class Million {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            int NoCus = 0;
            getCustomers(NoCus);
        }
     
      public static void getCustomers(int NoCus){
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter the number of customers");
          NoCus = sc.nextInt();
          System.out.println("Number of customers entered  = "+NoCus);
          getDetails(NoCus);
          }//end GetCustomers
     
      public static class Customer
    {
        String title;
        int accNo;
        int price;
        int sBal;
     
        // Add constructor, get, set, as needed.
    }
     
      public static void getDetails(int NoCus){
          ArrayList details = new ArrayList();
          for (int proCus =0; proCus != NoCus; proCus++){
              System.out.println("Enter customer details");
              Scanner sc = new Scanner(System.in);
              details.add(new Customer("Ernie", 454321, 78, 4999));
              //details.add(sc.next());
              System.out.println("You have entered"+details);
          }
     
      }//end getDetails
     
    }//end main


  2. #2
    Junior Member
    Join Date
    Jun 2014
    Posts
    22
    My Mood
    Starving
    Thanks
    1
    Thanked 8 Times in 6 Posts

    Default Re: errror constructor class cannot be applied to give types

    If you look inside your customer class you will see a comment:

    // Add constructor, get, set, as needed.

    So it looks like you are supposed to write code here. The error exists because the code you need to write does NOT exist.
    You need to write the methods(the Customer constructor also needs to be written. The constructor is what is being called where the error is, but the constructor hasn't been written yet) in the Customer class so that the call where you are getting the error is no longer an error.
    Last edited by koder632417; June 13th, 2014 at 12:00 AM.

  3. The Following User Says Thank You to koder632417 For This Useful Post:

    GregBrannon (June 13th, 2014)

  4. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    9
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: errror constructor class cannot be applied to give types

    Thx for the reply im new to this constructor thing can you help me get it right i have no idea how to code it i did everything myself except the customer class and i have no idea how to add the constructor

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: errror constructor class cannot be applied to give types

    Please refer to this tutorial and return with your updated code and any remaining questions.

  6. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    22
    My Mood
    Starving
    Thanks
    1
    Thanked 8 Times in 6 Posts

    Default Re: errror constructor class cannot be applied to give types

    I second what Greg said. Check out the link that he posted. The first page alone should give you enough information on how you need to define your constructor.

    A constructor looks like a method, it has no return type, and it has the same name as the class that it is in. They are called on (as in line 51 of your code) to create objects from your class.

    Not to throw everything at you at once, but after the constructor is created you will still most likely need set and get methods in the Customer class. Here is one link that could get you familiarized with what they look like: http://stackoverflow.com/questions/1...uctors-in-java

Similar Threads

  1. constructor and class
    By nepperso in forum Object Oriented Programming
    Replies: 5
    Last Post: November 25th, 2013, 09:54 PM
  2. [SOLVED] method in class cannot be applied
    By ange in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 30th, 2013, 05:03 AM
  3. How to avoid a constructor of class A be extended to Class B?
    By chaitra1987 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 28th, 2013, 11:46 PM
  4. **Constructor in class cannot be applied to given types;...
    By bassie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 2nd, 2012, 03:15 PM
  5. which class has a default constructor? (Req. guidance on constructor)
    By DragBall in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2012, 04:42 PM