- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发一个与狗一起使用的项目,我当前正在开发的方法应该让用户更改狗窝容量。下面的代码来自狗窝构造函数类:
public class Kennel {
private String name;
private ArrayList < Dog > dogs;
private int nextFreeLocation;
private int capacity;
/**
* Creates a kennel with a default size 20
*
* @param maxNoDogs
* The capacity of the kennel
*/
public Kennel() {
this(20);
}
/**
* Create a kennel
*
* @param maxNoDogs
* The capacity of the kennel
*/
public Kennel(int maxNoDogs) {
nextFreeLocation = 0; // no Dogs in collection at start
capacity = maxNoDogs;
dogs = new ArrayList < Dog > (capacity); // set up default. This can
// actually be exceeded
// when using ArrayList but we
// won't allow that
// to happen.
}
/**
* This method sets the value for the name attribute. The purpose of the
* attribute is: The name of the kennel e.g. "DogsRUs"
*
* @param theName
*/
public void setName(String theName) {
name = theName;
}
/**
* Set the size of the kennel
*
* @param capacity
* The max dogs we can house
* @return
*/
public void setCapacity(int capacity) {
if (this.capacity > capacity) {
this.capacity = capacity;
} else
System.out.println("The capacity you entered is lower than the current capacity");
}
/**
* Maximum capacity of the kennels
*
* @return The max size of the kennel
*/
public int getCapacity() {
return capacity;
}
/**
* This method gets the value for the name attribute. The purpose of the
* attribute is: The name of the Kennel e.g. "DogsRUs"
*
* @return String The name of the kennel
*/
public String getName() {
return name;
}
/**
* This method returns the number of dogs in a kennel
*
* @return int Current number of dogs in the kennel
*/
public int getNumOfDogs() {
return nextFreeLocation;
}
/**
* Enables a user to add a Dog to the Kennel
*
* @param theDog
* A new dog to home
*/
public void addDog(Dog theDog) {
if (nextFreeLocation >= capacity) {
System.out.println("Sorry kennel is full - cannot add team");
return;
}
// we add in the position indexed by nextFreeLocation
// This starts at zero
dogs.add(theDog);
// now increment index ready for next one
nextFreeLocation = nextFreeLocation + 1;
}
/**
* Enables a user to delete a Dog from the Kennel.
*
* @param theDog
* The dog to remove
*/
public void removeDog(String who) {
Dog which = null;
// Search for the dog by name
for (Dog d: dogs) {
if (who.equals(d.getName())) {
which = d;
}
}
if (which != null) {
dogs.remove(which); // Requires that Dog has an equals method
System.out.println("removed " + who);
nextFreeLocation = nextFreeLocation - 1;
} else
System.err.println("cannot remove - not in kennel");
}
/**
* @return String showing all the information in the kennel
*/
public String toString() {
StringBuilder sbr = new StringBuilder();
sbr.append("Data in Kennel " + name + " is:");
for (Dog d: dogs) {
sbr.append(d.toString() + "\n");
}
return sbr.toString();
}
/**
* Returns an array of the dogs in the kennels
*
* @return An array of the correct size
*/
public Dog[] obtainAllDogs() {
Dog[] result = new Dog[dogs.size()];
result = dogs.toArray(result);
return result;
}
/**
* Only returns those dogs who like bones
*
* @return An array of dogs of the correct size. If no dogs like bones then
* returns an empty array (size 0)
*/
public List < Dog > obtainDogsWhoLikeBones() {
List < Dog > result = new ArrayList < Dog > (); // changed to List<dog> so can
// freely add data without
// intializing to fixed size
for (Dog d: dogs) {
if (d.getLikesBones()) {
result.add(d);
}
}
return result;
}
public Dog search(String name) {
Dog result = null;
for (Dog d: dogs) {
if (name.equals(d.getName())) {
result = d;
}
}
return result;
}
}
这个方法来自狗窝应用程序类:
private void setKennelCapacity() {
System.out.print("Enter max number of dogs: ");
int max = scan.nextInt();
scan.nextLine();
kennel.setCapacity(max);
System.out.println(max + " " + kennel.getCapacity());
}
结果是运行else语句,总是说输入的数字太小。这可能是一个小错误,但我缺乏经验,感谢您的帮助。
最佳答案
usercapacity
是一个局部变量。每次调用setCapacity(int)
时,变量usercapacity
将被初始化为0
(该变量将始终为0)。相反,创建一个字段变量来存储容量
class Kernal {
private int capacity;
public void setCapacity(int newCapacity) {
if(newCapacity < capacity) {
throw new IllegalArgumentException("You cannot enter a value that is lower than the current capacity");
}
capacity = newCapacity;
}
}
<小时/>
如果没有IllegalArgumentException
(使用简单的打印语句来通知用户),您的方法将如下所示:
public void setCapacity(int capacity) {
if (this.capacity < capacity) {
this.capacity = capacity;
} else
System.out.println("The capacity you entered is lower than the current capacity");
}
关于java - 如何判断用户输入的容量是否大于当前容量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29502183/
我在 iOS 上有一个使用 WebSQL 数据库的 PhoneGap 应用程序。在某些地方,我读到存储容量是 5MB,而在其他地方,我读到它是 50MB,有人可以帮我解决这个问题吗?我还计划在数据库中
我想弄清楚如何更新节点的 pod 容量。我使用文档中概述的 Vagrant/VM 环境进行了简单的集群设置。我尝试使用 kubectl 修补节点的 pod 容量,执行以下操作: 通过以下方式发送补丁所
我想创建一个函数,根据某人系统上的可用 RAM 大小来导入不同批处理的数据。但是如何找到 R 中的可用 RAM 量呢?我可以使用 memory.size() 但这只适用于 Windows。 最佳答案
目前,我正在努力将 Power BI 内容嵌入到我的 Web 应用程序中。我已经通过服务主体实现了它,并且它按预期工作。但是对于产品环境,是否必须为我的报告或工作区添加容量?是否可以在不增加生产环境容
我有一个 3 节点 coros kubernetes 集群启动并运行。 我想使用来自独立 NFS 服务器的 persitentvolumes(pv)。 nfs.yaml apiVersion: v1
我正在学习golang一段时间。我遇到了 channel 问题。 我有两个例子。它们看起来一样,但是其中1个给出了错误。 当我分配 channel 容量(转换为缓冲 channel )时,问题已解决,
我正在尝试创建一个子例程,将一个字符串插入另一个字符串。我想检查主机字符串是否有足够的容量来容纳所有字符,如果没有,则返回错误整数。这需要使用类似 sizeof 的东西,但可以使用指针调用。我的代码如
这个问题在这里已经有了答案: size vs capacity of a vector? (8 个答案) 关闭 7 年前。 在下面的程序中,我只是创建了一个空 vector ,然后将大小调整为 5
免责声明 1 - 我是编程新手免责声明 2 - 我搜索了又搜索,但找不到我正在寻找的帮助。 对于一个项目,我或多或少地以更精简的形式重写了 vector 类。我挂断的部分是编写 push_back 方
我对 BTree 的理解是: if root BTree size is 32, the level 1 have 1024 keys capacity the level 2 can sort 10
我有一个使用 ActionBar 的应用程序,我自己处理方向更改: android:configChanges="keyboard|keyboardHidden|orientation|screenS
如何将 hadoop DFS 的配置容量从默认的 50GB 增加到 100GB? 我目前的设置是在 centOS6 机器上运行的 hadoop 1.2.1,使用了 450GB 中的 120GB。已使用
我的问题是关于 slice 长度和容量。我在这里学习 Go:https://tour.golang.org/moretypes/11 . (我的问题被标记为可能与 this 重复;但是,事实并非如此。
现在尝试从教程中学习 Go,并且有一个非常基本的问题: func main() { a := make([]int, 5) // [0,0,0,0,0] len=5 cap=5 b :=
如何以以下格式获取有关数据库中所有表空间的信息。 TABLESPACE_NAME | FILE_NAME | ALLOCATED_MB | FREE_MB | CAPACITY | 有没有办法自
我想基于每个作业更改群集的减少插槽容量。也就是说, 最初,我为Tasktracker配置了8个reduce插槽,因此对于具有100个reduce任务的作业,将同时运行(8 * datanode数量)r
我正在运行单节点 Hadoop 部署。我知道我的应用程序需要多少数据,我可以设置(和重新设置)HDFS 使用的最大容量吗? 我已经尝试了以下方法,但似乎无法实现。 检查 hdfs-site.xml 和
我安装了 splunk 来监控和分析 hadoop 作业。我在其他节点的Jobtracker、forwarder和TA中安装splunk core和splunk hadoop app后,HDFS ca
vector::operator= 会改变 vector 容量吗?如果有,怎么做? vector的拷贝构造函数是否拷贝容量? 我查看了文档,但找不到具体答案。是否依赖于实现? 最佳答案 您可以保证:
将 SQL 数据库导出到存储时,我们的 DTU 容量已达到,这本质上意味着我们的系统性能受到严重影响。 这对我们来说是一个问题,因为我们使用导出功能来备份和移动数据库。 这个问题有解决办法吗? 最佳答
我是一名优秀的程序员,十分优秀!