简体   繁体   English

从给定号码创建的清单中删除号码

[英]Removing a number from a listed created by given numbers

so here's the details. 这是详细信息。 I'm coding using java - BlueJ, and currently have a main class Auction, and a few other classes: Lot, Person, Bid 我正在使用java-BlueJ进行编码,并且目前有一个主要的拍卖类,以及其他几个类:Lot,Person,Bid

The purpose of the program is to enter items into the auction, along with their prices, where the information will be stored according to whether it's price, person, or item name/description. 该程序的目的是将物品及其价格输入拍卖中,然后根据价格,人或物品名称/描述将信息存储在拍卖中。

This is the code for my getLot method - user inputs lot number, and it shows info for the lot, which I assume should also be the starting point for the removeLot method since it should still check if the lot number given is valid first. 这是我的getLot方法的代码-用户输入批号,它显示批号的信息,我认为这也应该是removeLot方法的起点,因为它仍应首先检查给出的批号是否有效。

I'm trying to figure out how to add a removeLot method so that I can remove an item from the lot by typing in its lot number. 我试图弄清楚如何添加removeLot方法,以便可以通过输入批号从批号中删除项目。

This is the code I have for that section. 这是该部分的代码。

public Lot removeLot(int number)
 {
    if((number >= 1) && (number < nextLotNumber)) {
        // The number seems to be reasonable.
        Lot selectedLot = lots.get(number - 1);
        // Include a confidence check to be sure we have the
        // right lot.
        if(selectedLot.getNumber() != number) {
            System.out.println("Internal error: Lot number " +
                selectedLot.getNumber() +
                " was returned instead of " +
                number);
            // Don't return an invalid lot.
            selectedLot = null;
        }
        **else {
        Lot.removeIf(selectedLot.getNumber() = number);**
        }
        return selectedLot;

The else block with the "**" is what I added, wanting to remove the given number. 我添加了带有“ **”的else块,想要删除给定的数字。 But it's clearly wrong, and I'm not sure what to do. 但这显然是错误的,我不确定该怎么做。

If the datatype of lots variable is List than you can try below code 如果lots变量的数据类型为List ,则可以尝试以下代码

public Lot removeLot(int number)
 {
    Lot selectedLot=null;
    if((number >= 1) && (number < nextLotNumber)) {
        // The number seems to be reasonable.
        selectedLot = lots.get(number - 1);
        // Include a confidence check to be sure we have the
        // right lot.
        if(selectedLot.getNumber() != number) {
            System.out.println("Internal error: Lot number " +
                selectedLot.getNumber() +
                " was returned instead of " +
                number);
            // Don't return an invalid lot.
            selectedLot=null;
        }
        else {

            if(selectedLot.getNumber() = number)
                {
                    lots.remove(number-1);
                }

        }
        return selectedLot;
}

Lot.removeIf(selectedLot.getNumber() = number) is not correct Lot.removeIf(selectedLot.getNumber()=数字)不正确
you can try: 你可以试试:

} else if(selectedLot.getNumber() == number) {
   Lot.removeIf(selectedLot.getNumber());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将所有数字的总和从给定数字添加到给定数字? - add the sum of all numbers from a given number to a given number? 如何从给定的四个数字中生成一个唯一的数字,以及如何从生成的唯一数字中获取这些给定的数字? - How to generate an unique number from a given four numbers and getting these given numbers back from generated unique number? 查找从给定客户端IP创建的活动会话数 - Find number of active sessions created from a given client IP Java程序,用于对列表中给定数字的连续编号进行分组<list> - Java program to group consecutive number from given numbers in a list<list> 如何使用给定的数字列表中的Java生成随机数 - How to generate a random number with Java from given list of numbers 从数字中删除小数 - Removing decimals from the numbers 优化代码以从给定数量的差异中找出组合的总数? - Optimizing code for finding total number of combination from given numbers whose difference is given? 如何从输入数字的给定数字列表中找到下一个相邻的更大数字 - How to find next adjacent bigger number from given list of numbers for an input number 给定一个数字,返回具有非重复数字的数字的计数,直到该数字从1开始? - Given a number, return the count of numbers having non-repeating digits till that number starting from 1? 我正在尝试从用户那里找到从 0 到给定数字的素数 - I am trying to find the prime numbers from 0 to a given number from the user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM