有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在ArrayList中使用索引添加多个对象

我正在做一个基于菜单的系统,它将使用特定的变量(双月租金、双水租金、双能源租金等)计算我的月租金

程序首先提示用户选择一个选项:

(1)创建预算发票(这是计算预计月租金发票的地方)

当用户选择此选项时,我希望使用ArrayList存储每月租金发票。我有一个变量,用户可以在其中输入InvoiceID来搜索已经存在的月租金发票或删除等

我的问题是如何使用ArrayList中的特定索引输入月租金、水费等,下一个索引将是不同的月租金、水费、能源费等)。一般来说,在ArrayList的1个索引中存储多个变量和变量类型

我的ArrayList在它自己的类中,不同于我想要创建以生成月度预算发票的函数。我的问题是如何提示用户输入每个租金变量,并将所有这些输入存储在ArrayList的适当索引中,在该索引中将存储特定的月度发票。变量是double、string和int类型

import java.util.ArrayList;

public class InvoicerHub {

    
    static ArrayList<Object> invoicerSys = new ArrayList<Object>();
    
}
import java.util.ArrayList;
import java.util.Scanner;

public class BudgetInvoice extends InvoicerHub {

    protected double monthlyRent ;
    
    protected double waterBill;
    
    protected double energyBill;
    
    protected double carRent; 
    
    protected double internetRent;
    
    protected String invoiceID;

     public int counter = 0; 
     
     
    static Scanner myScan= new Scanner(System.in);
    
    
    
    public double getMonthlyRent() {
        return monthlyRent;
    }

    public void setMonthlyRent(double monthlyRent) {
        this.monthlyRent = monthlyRent;
    }

    public double getWaterBill() {
        return waterBill;
    }

    public void setWaterBill(double waterBill) {
        this.waterBill = waterBill;
    }

    public double getEnergyBill() {
        return energyBill;
    }

    public void setEnergyBill(double energyBill) {
        this.energyBill = energyBill;
    }

    public double getCarRent() {
        return carRent;
    }

    public void setCarRent(double carRent) {
        this.carRent = carRent;
    }

    public double getInternetRent() {
        return internetRent;
    }

    public void setInternetRent(double internetRent) {
        this.internetRent = internetRent;
    }

    public String getInvoiceID() {
        return invoiceID;
    }

    public void setInvoiceID(String invoiceID) {
        this.invoiceID = invoiceID;
    }
    
    
    
    public static InvoicerHub getInvoice() 
    
    {
        
        
        invoicerSys = new ArrayList<>();
        
        if (invoicerSys.isEmpty()== true) 
        {
            
        } // This is where I'm stuck. 

共 (0) 个答案