有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java错误消息:缺少方法体或声明抽象,如何修复?

您好,我收到错误消息:缺少方法体或声明抽象,如何修复此问题,这意味着什么

我的代码:

public class Mobile

{
    // type of phone
private String phonetype;
    // size of screen in inches
private int screensize;
    // memory 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 chargeUp;
    // wether the phone has GPS or not
private int switchedOnFor;
    // to simulate using phone for a period of time
private int charge;
    // checks the phones remaining charge
private String provider;
    // simulates changing the provider
private String GPS; 
    // instance variables - replace the example below with your own
private int cost; 
    // declares cost of the item     


  // The constructor method

public Mobile(String mobilephonetype, int mobilescreensize,
int mobilememorycardcapacity, String mobileServiceProvider, int mobileTypeOfContract, int mobilecameraresolution, String mobileGPS, int chargeUp,int switchedOnFor, String changeProvider,int getBalance, int cost,int price) {
     // initialise the class attributes from the one given as parameters in your constructor.
}


/**
* Other constructor
*/
public Mobile (int cost){
    price = 1000;
    // initialise cost(?) attribute that actually doesn't seem to exist?
}

 /**
*returns a field price.
    */
public int getcost()
   {
return balance;
    }
     /**
    *return the amount of change due for orders of mobiles. 
    */
   public int getBalance()
   {
       return balance;
    }
/**
     * Receive an amount of money from a customer.
     */
    public void cost (int price)
    {
        balance = balance + amount;
    }



        //this.serviceprovider = newserviceprovider;
        //this.typeofcontract = 12;
        //this.checkcharge = checkcharge;
        //this.changeProvider = giffgaff;

  //Mobile samsungPhone = new Mobile(
 //   "Samsung" // String mobilephonetype
//,   1024    // intmobilescreensize
//,   2      // intmobilememorycardcapacity
//,   8       // intmobilecameraresolution
//,   "GPS"    //String mobileGPS
//,   "verizon" // String newserviceprovider
//,    "100" // intchargeUp
//,    "25" // intswitchedOnFor
//,    "25" // intcheckCharge
//,     "giffgaff"// String changeProvider
//);


        //typeofcontract = 12;
        //checkcharge = checkcharge;


    //Mutator for newserviceprovider
public void setmobileServiceProvider(String newmobileServiceProvider)
   {
mobileServiceProvider = newmobileServiceProvider;
   }
   //Mutator for contracttype
public void setmobileTypeOfContract(int newmobileTypeOfContract)
   {
mobileTypeOfContract = newmobileTypeOfContract;
   }
   //Mutator for chargeUp
public void setchargeUp(int chargeUp)
   {
this.chargeUp = chargeUp;
   }
   //Mutator to simulate using phone for a period of time
public void switchedOnFor(int switchedOnFor)
   {
this.switchedOnFor = switchedOnFor;
    }
   //Accessor for type of phone
public String getType()
   {
return phonetype;
   }
   //Accessor for provider
public String getprovider()
   {
return mobileServiceProvider;
   }
   //Accessor for contract type
public int getContractType()
   {
return mobileTypeOfContract;
   }
    //Accessor for charge
public int getCharge()
   {
return chargeUp;
   }
    //Accessor which checks the phones remaining charge
public int checkCharge()
   {
return checkCharge;
   }
    // simulates changing the provider
public void changeProvider()
   {
provider = changeProvider;
   }
//returns the amount of change due for orders of mobiles. 
public int Balance()
   {
return balance;
   }
    // 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,12,"GPS",100,25,"giffgaff");  
Mobile Blackberry = new Mobile("Samsung",3,4,"verizon",8,12,"GPS",100,25,"giffgaff");     
}    
public static void main(String[] args) {
buildPhones();
}  

}

任何答案、回复和帮助都将不胜感激,因为我无法像以前那样编译它,而且没有语法错误


共 (3) 个答案

  1. # 1 楼答案

    public Mobile (int cost); {
        price = 1000;
        // initialise cost(?) attribute that actually doesn't seem to exist?
    }
    

    在这里,你留下了一个分号,删除它

    public Mobile (int cost){
        price = 1000;
        // initialise cost(?) attribute that actually doesn't seem to exist?
    }
    
  2. # 2 楼答案

    检查第42行声明的构造函数。它没有身体

    public Mobile (int cost); {
        price = 1000;
        // initialise cost(?) attribute that actually doesn't seem to exist?
    }
    

    此外,price和许多其他字段没有在任何地方声明

  3. # 3 楼答案

    从中删除;

    public Mobile (int cost); {