Results 1 to 2 of 2
  1. #1
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default constructor Mobile in class Mobile cannot be applied to given types; required: java..

    error message saying constructor Mobile in class Mobile cannot be applied to given types; required: java.lang.String,int,java.lang.String,int,java.lan g.String,int; on Line 91: Mobile Samsung = new Mobile("Samsung",3,4,"verizon",8,"GPS");

    my code:

    Java Code:
    /**
     * to write a simple java class Mobile that models a mobile phone.
     * 
     * @author (jamal) 
     * @version (1/10/13)
     */
    public class Mobile
    
    {
        // type of phone
        private String phonetype;
        // size of screen in inches
        private int screensize;
        // menory card capacity
        private int  memorycardcapacity;
        // name of present service provider
        private String mobileServiceProvider;
        // type of contract with service provider
        private int mobileTypeOfContract;
        // camera resolution in megapixels
        private int cameraresolution;
        // the percentage of charge left on the phone
        private int checkcharge;
        // wether the phone has GPS or not
        private String GPS;
        // instance variables - replace the example below with your own
        private int x;
    
        // The constructor method
    
        public Mobile(String mobilephonetype, int mobilescreensize,
                int mobilememorycardcapacity, String mobileServiceProvider, int mobileTypeOfContract, int mobilecameraresolution, String mobileGPS) {
            this.phonetype =  mobilephonetype;
            this.screensize = mobilescreensize;
            this.memorycardcapacity = mobilememorycardcapacity;
            this.mobileServiceProvider = mobileServiceProvider;
            this.mobileTypeOfContract = 12;
            this.cameraresolution = mobilecameraresolution;
            this.GPS = mobileGPS;
             
            // you do not use this ones during instantiation,you can remove them if you do not need or assign them some  default values 
            //this.serviceprovider = newserviceprovider;
            //this.typeofcontract = 12;
            //this.checkcharge = checkcharge;
    
      // Mobile samsungPhone = new Mobile(
     //   "Samsung" // String mobilephonetype
    //,   1024    // int mobilescreensize 
    //,   2      // int mobilememorycardcapacity 
    //,   8       // int mobilecameraresolution 
    //,   "GPS"    //String mobileGPS
    //,   "verizon" // String newserviceprovider 
    //);
    
    
            //typeofcontract = 12;
            //checkcharge = checkcharge;
            
        }
        //Mutator for newserviceprovider
       public void setmobileServiceProvider(String mobileServiceProvider)
       {
         this.mobileServiceProvider = mobileServiceProvider;
       }
       //Mutator for contracttype
       public void setmobileTypeOfContract(int mobileTypeOfContract)
       {
         this.mobileTypeOfContract = mobileTypeOfContract;
       }
        // A method to display the state of the object to the screen
        public void displayMobileDetails() {
            System.out.println("phonetype: " + phonetype);
            System.out.println("screensize: " + screensize);
            System.out.println("memorycardcapacity: " + memorycardcapacity);
            System.out.println("cameraresolution: " + cameraresolution);
            System.out.println("GPS: " + GPS);
            System.out.println("mobileServiceProvider: " + mobileServiceProvider);
            System.out.println("mobileTypeOfContract: " + mobileTypeOfContract );
    } 
    
          /**
     * The mymobile class implements an application that
     * simply displays "new Mobile!" to the standard output.
     */
    public class mymobile {
        public void main(String[] args) {
            System.out.println("new Mobile!"); //Display the string.
        }
    }
        public static void buildPhones(){
        Mobile Samsung = new Mobile("Samsung",3,4,"verizon",8,"GPS"); 
        Mobile Blackberry = new Mobile("Blackberry",3,4,"verizon",8,"GPS");   
    }
        public static void main(String[] args) {
            buildPhones();
    }  
           
    }


    any answers or replies and help would be greatly appreciated as I really lost!, and cant get it to compile like it did before with no syntax errors.

  2. #2
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default Re: constructor Mobile in class Mobile cannot be applied to given types; required: ja

    You are passing an incorrect argument sequence to your constructor. You need to pass another int argument after mobileServiceProvider, as you are only passing one in both of your mobile objects.
    (String mobilephonetype, int mobilescreensize, int mobilememorycardcapacity, String mobileServiceProvider, int mobileTypeOfContract, int mobilecameraresolution, String mobileGPS)
    Mobile Samsung = new Mobile("Samsung",3,4,"verizon",8, (need another int here),"GPS");

    hope this helps ya!

Similar Threads

  1. Replies: 13
    Last Post: 07-03-2013, 05:23 PM
  2. I want to secure my Mobile Class Library source code
    By navab1362 in forum CLDC and MIDP
    Replies: 0
    Last Post: 03-02-2013, 02:05 PM
  3. Replies: 6
    Last Post: 10-06-2012, 02:21 AM
  4. Replies: 3
    Last Post: 10-01-2011, 09:29 PM
  5. Replies: 1
    Last Post: 08-07-2009, 12:14 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
  •