- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在做作业,我有两个类(class)“房间”和“房子”。作为作业的一部分,我需要启用房屋类将房间存储在 ArrayList
中。 :
Implement a method to read in room information in the
House
class from the keyboard — this should call theRoom
constructor as required. Create a zero-argument House constructor to call this new method.
如果这含糊不清或已在其他地方得到回答,我深表歉意,但在尝试理解其他类似查询的解释后,我不知道如何将它们应用到我的情况。
如何申请ArrayList
的Room
去家庭类吗?
<强> House
:
import java.util.ArrayList;
import java.util.Scanner;
public class House {
private int idNum;
private static int internalCount = 0;
private ArrayList rooms = new ArrayList();
private String address;
private int numRooms;
private String houseType;
public House (String address, int numRooms, String houseType) {
idNum = internalCount++;
this.address = address;
this.numRooms = numRooms;
this.houseType = houseType;
}
public House () {
int i = 0;
idNum = ++internalCount;
Scanner scan = new Scanner(System.in);
scan.useDelimiter("\n");
System.out.println("Enter address of house:");
address = scan.next();
System.out.println("Enter number of rooms:"); //Number of rooms in the House
numRooms = scan.nextInt();
while (i < numRooms) //This will loop until all rooms have been described
{
add.room = new Room[100]; //I understand this is incorrect but I don't know what I should have in here
i++;
}
System.out.println("Enter type of house:");
houseType = scan.next();
}
public void addroom(String description, double length, double width)
{
}
int getIdNum() {
return idNum;
}
@Override
public String toString()
{
String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
report += "Address: " + address + "\n";
report += "No. of Rooms: " + numRooms + "\n";
report += "House Type: " + houseType+ "\n";
report += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
return report;
}
}
<强> Room
:
import java.util.Scanner;
public class Room {
private String description;
private double length;
private double width;
public Room (String description, double length, double width) {
this.description = description;
this.length = length;
this.width = width;
}
public Room () {
Scanner scan = new Scanner(System.in);
scan.useDelimiter("\n");
System.out.println("Enter description of room:");
description = scan.next();
System.out.println("Enter length of room:");
length = scan.nextDouble();
System.out.println("Enter width of room:");
width = scan.nextDouble();
}
/*
* Calculates and returns area of Room
*/
public double getArea () {
return length*width;
}
@Override
public String toString() {
return description + "- Length: " + length + "m; Width: " + width + 'm';
}
}
最佳答案
您检查过API吗?对于数组列表?
你需要这样的东西:
rooms.add(new Room());
此外,我将利用 Java 泛型并这样定义列表:
private ArrayList<Room> rooms;
这利用了 generics ,并确保这只能是房间列表,而不是杂项对象。这将为您省去一些麻烦,因为您不会无意中将房屋添加到房间列表中(通过编程错误)
关于java - 如何实现 ArrayList 将 "Room"对象添加到 "House"对象列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15368415/
我正在编写一个正则表达式,需要满足以下条件。 (name="myName".*house="myHouse"|house="myHouse".*name="myName") 名字或房子都可以放在第一位
所以我刚开始使用 Applets,当 applet 加载时,我正在制作一扇打开的门和 2 个打开的 window 的房子。当您单击这些 window 或门时,它们将关闭。不过,我的问题是我需要做什么才
我正在做 House Robber challenge . You are a professional robber planning to rob houses along a street. E
我正在尝试使用R从API提取文档。感谢this post中过程的澄清。我一直遵循上述步骤取得了部分成功,但是仍然无法通过最后一步获得对文档内容的访问权限: Find the document fili
关于苹果文档,企业程序允许在内部分发应用程序。 Apple 如何区分内部用户和内部用户?合作伙伴公司? 或者这只是法律协议(protocol)中的一段,将内部分发定义为仅允许公司成员使用? 最佳答案
我已经为 3 个字段中的一小部分记录设置了全文索引(也尝试了 3 个字段的组合并得到了相同的结果),有些词返回结果很好,但某些词如“house” ' 和 'australia' 没有(有趣的是,'au
我有一个用于存储房地产的 NoSQL 系统。 我在每个房子的键值存储中的一条信息是经度和纬度。 如果我想检索地理纬度/经度框中的所有房屋,如下面的 SQL: SELECT * from houses
让我们承认,我在 100 部 iPhone 上部署了一个应用程序,使用的是苹果“内部”部署的企业程序。所有这些都将连接到互联网。分发证书到期后会发生什么?我的所有员工都需要再次下载该应用程序,并使用新
我知道像这样的问题已经被问了一遍又一遍,但我找不到直截了当的答案。 我看过guides这似乎允许您分发您的应用 OTA,而无需成为企业计划的一部分。 我还看到了一些技巧,如果您的主机中没有 SSL 证
我在翻译这句话时遇到了问题: “运行内部系统意味着您可以 利用您现有的安全系统进行身份验证、授权等”——来自 Pro C# 2010 和 .NET 4 平台 谷歌翻译对我没有帮助。 我不想把它翻译成我
我目前是一个Python新手,正在使用Python创建一些游戏。我编写了一个游戏“纸牌屋”,基本上我正在尝试使用我在 OOP 中学到的知识来完成它。规则非常简单——你需要最大的牌才能获胜。玩家首先比较
我正在开发一款使用 Amazon Web Services 将视频上传到 S3 的 iPhone 应用程序。我可以有小尺寸的视频或大尺寸的视频。在上传过程中,有时会完全挂起,只是停顿,没有任何错误或超
我有一个可以使用 Enterprise Distribution 通过 S3 Bucket 下载的应用程序,它第一次失败并显示正在加载,但是当我使用配置实用程序通过将设备连接到计算机来手动安装证书时,
我的一位客户在他的招标规范中提到了“数据库管理”一词。我不确定这个词,请帮助。 最佳答案 应该是: 索引重建或重组 统计更新 DBCC CHECKDB(检查完整性等)-等等 其他内容: 检查磁带/离线
题目地址:https://leetcode.com/problems/house-robber-iii/description/ 题目描述 Thethief has found himself a
题目地址:https://leetcode.com/problems/house-robber-ii/description/ 题目描述: Youare a professional robber
Click House 中的 Store 文件夹是什么? Click House中有一个名为Store的文件夹,它的体积非常大。 虽然我没有更多的数据库并且其大小为 1 GB,但 Store 文件夹几
使用 XSL-FO 时,有没有一种方法可以防止单词在分页符上连字符,而一般的连字符是打开的?我正在使用 Antenna House Formatter。提前谢谢你。 最佳答案 抱歉,不,我不知道有什么
我想知道是否有人知道如何在 java 中实现代码来打印所有满堂彩的情况。大约有 3700 种不同的情况。到目前为止,我大约有 2700 点,但我在更换西装时遇到了麻烦,她就是我目前所拥有的。 publ
我不是在问这里的代码!我问的是这里的流程。 我想通过 XML gateway of Companies House 搜索公司名称可用性。我知道如何在 Java 中使用 jabx 编码和解码数据,但我不
我是一名优秀的程序员,十分优秀!