- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个添加/删除不同类型客户的简单程序。
我知道这可能很简单,但已经困扰我一段时间了。
继续出现错误,
constructor Customer in class Customer cannot be applied to the given types; required; java.lang. String, Address, char found:no arguments reason: actual and formal argument lists differ in length
我猜这与客户构造函数有关,但不知道。
public class Address
{
private String street,town;
/**
* Constructor for Address
*
* @param street The street
* @param town The town
*/
public Address (String street, String town)
{
this.street = street;
this.town = town;
}
/**
* @return The street
*/
public String getStreet()
{
return street;
}
/**
* @return The town
*/
public String getTown()
{
return town;
}
/**
* Change the street part of the address
*
* @param street The new street
*/
public void setStreet(String street)
{
this.street = street;
}
/**
* Change the town part of the address
*
* @param street The new town
*/
public void setTown(String town)
{
this.town = town;
}
public String toString()
{
return street + "\n" + town;
}
}
public class Name
{
private String fName, lName;
/**
* Constructor for Name
*
* @param fName The first name
* @param lName The last name
*/
public Name(String fName, String lName)
{
this.fName = fName;
this.lName = lName;
}
/**
* @return The first name
*/
public String getFName()
{
return fName;
}
/**
* @return The last name
*/
public String getLName()
{
return lName;
}
/**
* Amend the first name
*
* @param fName The new first name
*/
public void setFName(String fName)
{
this.fName = fName;
}
/**
* Amend the last name
*
* @param lName The new last name
*/
public void setLName(String lName)
{
this.lName = lName;
}
public String toString()
{
return fName + " " + lName;
}
}
public class Customer
{
// instance variables - replace the example below with your own
private String accountNumber;
private Address address;
private int balance;
private char customerType;
/**
* Constructor for objects of class Customer
*/
public Customer(String accountNumber, Address address, char customerType)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address= address;
balance = 0;
this.customerType=customerType;
}
/**
* Adds money to the ammount in the account
*/
public void credit(int amt)
{
balance= balance + amt;
}
/**
* removes money from the ammount in the account
*/
public void debit(int amt)
{
balance= balance - amt;
}
/**
* Returns the account number of the customer
*/
public String getAccountNumber()
{
return accountNumber;
}
/**
* returns the address of the customer
*/
public Address getAddress()
{
return address;
}
/**
* returns the balance of the customer
*/
public int getBalance()
{
return balance;
}
/**
* Returns the type of customer Bussiness or Personal
*/
public char getCustomerType()
{
return customerType;
}
public void setAddress(Address address)
{
this.address=address;
}
public String toString()
{
String output ="Account Number: " + accountNumber + "Customer Type: " + customerType + "balance: " + getBalance() + "Address: " + super.toString();
return output;
}
}
public class PersonalCustomer extends Customer
{
// instance variables
private Name name;
public PersonalCustomer(String accountNumber, Address address, Name name)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address=address;
this.name= Name;
}
public Name getName()
{
return + "Address: " + super.toString();
}
public void print()
{
System.out.println(toString());
}
public String toString()
{
String output = getFName() + getLName() + "\n" + "Account Number: " + accountNumber + "\n"
+ "Customer Type: " + customerType + "\n" + "Address: " + super.toString() + "\n"
+ "balance: " + getBalance();
return output;
}
}
最佳答案
错误消息显示您正在调用:
new Customer();
但客户需要字符串、地址和字符,例如:
new Customer("Bob", new Address("Cool Street","Awesome Town"), 'a');
这看起来有点奇怪,但原因是如果您不这样做,您的子类会隐式调用父构造函数。
public PersonalCustomer(String accountNumber, Address address, Name name)
{
// super(); //calls the parent constructor with no arguments without you seeing
this.accountNumber= accountNumber;
this.address=address;
this.name= Name;
}
您需要做的就是将 PersonalCustomer 构造函数更改为
public PersonalCustomer(String accountNumber, Address address, Name name)
{
super(accountNumber, address, 'p'); //or whatever customer type they are supposed to get
this.name= Name;
}
关于java - 无法编译个人客户类,构造函数有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15121706/
我有一个名为 flightbooking 的表。该表由字段组成,包括标有“R”或“C”的状态、已保留和已取消。 我想弄清楚的是允许删除状态为“C”的记录,但如果下一行的状态为“R”,则不应删除。 [编
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 1年前关闭。 Improve this
研究 PHP/Gearman。我试图了解 Gearman 服务器/进程如何确定什么构成“有效”客户端。 在我看过的文档中,文档显示了许多连接到 Gearman 服务器的客户端。但是,我没有找到任何描述
HBase案例:客户/订单 假设HBase 用于存储客户和订单信息。有两种核心记录类型被摄取:客户记录类型和订单记录类型。 客户记录类型将包含您通常期望的所有内容: 客户编号 客户名称
当运行配方时出现问题并且客户端运行中途挂起时,安装的 Chef 客户端将无法使用。 然后,您可以退出机器、重新启动、清理 Chef pid 文件等,但每次启动 Chef 客户端时都会显示以下消息: C
我正在用Java开发游戏,目前进展顺利。我想尽早实现多人游戏,因此我在此基础上进行构建,而不是在具有大量不同功能的情况下将整个游戏移植到多人游戏中。 我想使其成为客户端/服务器应用程序。 现在,我确定
我正在尝试以编程方式修改 magento 上的现有客户数据,但出现错误,希望有人可以帮助我。 require_once('../app/Mage.php'); ini_set("error_repor
我正在学习 JQuery。我需要创建一个自定义控件。该控件基本上将呈现一些 HTML。有时,我只想获取 HTML。我希望使用以下语法: // Put generated html inside of
我正在尝试以编程方式修改 magento 上的现有客户数据,但出现错误,希望有人可以帮助我。 require_once('../app/Mage.php'); ini_set("error_repor
我想选择表格的一行并插入到另一个现有表格中。(我用的是php和MySql,两张表除了id和timestamp外,其他列都是一样的) 我试着做一个手推车。我希望当有人付款时,从“carret”中选择该客
我想使用 JXTA 实现客户端-服务器架构。服务器部分的配置也将是 3 层。有谁知道开始这个项目的好地方吗? 提前致谢。 最佳答案 JXTA 处理 p2p 连接。这与客户端-服务器方法相反。 据我了解
我需要创建一个 Stripe 客户并为他们订阅一个计划。我查看了 Stripe.js,似乎虽然您可以获得 token ,但除此之外它没有提供任何东西。有可用于节点和 PHP 的库,但为什么不能用于 J
我有一个数据库设计要求,它变得越来越复杂,我需要找出最佳的处理方法。 目前,我有“联系人”,也有“公司”。一个公司可以有多个联系人,但一个联系人只能属于一个公司。这形成了明显的 1:n 关系。但是,联
http://ecc.galengrover.com/programs/facility-rentals/ 在那个页面上,只有那个页面我有一个奇怪的问题。在内容框上方,“所有区域”一词出现在其他文本的
所以,我让这个 CSS 预加载器正常工作。但是,我在将其添加到我的网站时遇到了一些困难。有人可以帮助我理解代码的实现,以允许预加载器成为网站加载前查看的第一个元素。此时预加载器将淡出。预加载器的代码如
考虑以下场景: 有一个 Windows 服务托管一个 WCF 服务。 WCF 服务在客户端和位于不同物理机器上的 AppFabric 服务器之间提供接口(interface)。它检索对象,对其进行计算
当前端的订单历史页面 (*/sales/order/history/) 只显示一条短消息时,这个问题首先被意识到:您没有下订单。 经过一番调试,发现问题出在这个函数上: Mage::getSingle
我的公司是一些项目的定制开发商店,有些较大,有些较小。目前,我们通过电子邮件处理所有客户通信。所以我们通过电子邮件发送设计文档,他们将其标记并发送回去。然后我们推出了他们产品的测试版,他们通过电子邮件
我有一个小部件 View 如下: 公共(public)类 RemoteNumView 扩展了 FrameLayout { 我如何调用 Roboguice 就像在 RoboActivity 中一样?如下
我有一个包含客户编号、客户名称和商品编号的 MySQL 表。它比这稍微复杂一点,但我尝试稍微简化它并删除敏感数据。 当前表 Unique Customer Number | Customer Name
我是一名优秀的程序员,十分优秀!