gpt4 book ai didi

java - 错误消息找不到符号 - 变量 mobileserviceprovider

转载 作者:太空宇宙 更新时间:2023-11-04 07:19:47 25 4
gpt4 key购买 nike

我已经成功编译了我的代码:

/**
* to write a simple java class Mobile that models a mobile phone.
*
* @author (jamal)
* @version (20/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 serviceprovider;
// type of contract with service provider
private int typeofcontract;
// 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,int mobilecameraresolution,String mobileGPS, String newserviceprovider) {
this.phonetype = mobilephonetype;
this.screensize = mobilescreensize;
this.memorycardcapacity = mobilememorycardcapacity;
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;

}

// 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("serviceprovider: " + serviceprovider);
System.out.println("typeofcontract: " + typeofcontract);
}

/**
* 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, 8, "verizon",
"GPS");
Mobile Blackberry = new Mobile("Blackberry", 3, 4,
8, "verizon", "GPS");
}
public static void main(String[] args) {
buildPhones();
}

}

但是当我尝试添加此代码时:

//Mutator for newserviceprovider
public void setnewserviceprovider(String newserviceprovider)
{
this.newserviceprovider = newserviceprovider;
}

//Mutator for contracttype
public void setcontracttype(String contracttype)
{
this.contracttype = contracttype;
}

添加上述代码:

   /**
* 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 typeofcontract;
// 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 mobilecameraresolution, String mobileGPS) {
this.phonetype = mobilephonetype;
this.screensize = mobilescreensize;
this.memorycardcapacity = mobilememorycardcapacity;
this.mobileServiceProvider = mobileServiceProvider;
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;
}

// 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("typeofcontract: " + typeofcontract);
}

/**
* 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, 8, "verizon",
"GPS");
Mobile Blackberry = new Mobile("Blackberry", 3, 4,
8, "verizon", "GPS");
}
public static void main(String[] args) {
buildPhones();
}

}

我收到错误消息无法找到符号 - 变量 mobileserviceprovider

任何答案和帮助将不胜感激,因为我真的迷失了!

最佳答案

编译错误告诉您,Mobile 类中没有名为 mobileserviceprovider 的类实例变量。添加

private String mobileServiceProvider;

Java 命名约定表明变量使用驼峰命名法来命名变量,例如mobileServiceProvider

阅读

关于java - 错误消息找不到符号 - 变量 mobileserviceprovider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19484403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com