我(作为一个绝对的初学者)正在尝试创建一个简单的工具,它可以创建一些对象并将它们链接起来。这些对象是:客户许可证(2 种类型,扩展类)
这个想法是在创建许可证时使用(其中一个)客户公司名称,因此许可证链接到客户。我使用 ArrayLists 来存储数据。
我尝试使用 Customer cCompany 的 getter,但是当我尝试实际创建一个新的许可证对象时,我收到有关不兼容类型的错误(String to object of type customer)
我该如何修复该错误?
非常感谢任何帮助,但请解释清楚,我是一个绝对的初学者。我可能把事情复杂化了……
部分代码摘录:
从主要:
public class Main {
public static void main(String[] args) {
//Create customers
List <Customer> customers = new ArrayList <> (10);
customers.add(new Customer("TestCompany","John Doe",1234567890,"John@testcompany.com"));
....
//Create Elvis licenses (based on superclass License)
List <ElvisLicense> ellicenses = new ArrayList <> (10);
ellicenses.add(new ElvisLicense("TestCompany","VendorA",1234,"1234-A","Solutions Server gold","1234-dtbk-87654-nlof",10, true , true));
类别: 客户:
class Customer {
String cCompany;
private String cName;
private int cPhone;
private String cEmail;
public Customer( String cCompany, String cName,int cPhone, String cEmail)
{
this.cCompany = cCompany;
this.cName = cName;
this.cPhone = cPhone;
this.cEmail = cEmail;
}
//This getter should be used to link the license to the customer (Done in License.java)
public String getcCompany() {
return cCompany;
}
类许可证(超类)
class License {
// Used no modifier to set access for Class/Package and Subclass inside the package
Customer licenseCompany;
String lVendor;
int lContractNumber;
String lCertificateNumber;
String lProductName;
String lLicenseKey;
int lNumberOfSeats;
public License(Customer cCompany, String lVendor, int lContractNumber, String lCertificateNumber,
String lProductName, String lLicenseKey, int lNumberOfSeats)
{
licenseCompany = cCompany;
this.lVendor = lVendor;
this.lVendor = lVendor;
this.lContractNumber = lContractNumber;
this.lCertificateNumber = lCertificateNumber;
this.lProductName = lProductName;
this.lLicenseKey = lLicenseKey;
this.lNumberOfSeats = lNumberOfSeats;
}
qq_遁去的一_1
FFIVE
慕田峪9158850
随时随地看视频慕课网APP
相关分类