使用方法向方法添加值

时间:2016-02-19 15:23:11

标签: java oop

我是OOP的新手,我碰到了一堵砖墙。我一直在尝试并试图获得一个进入价格房屋并增加费用和税收的计划。下面的代码很难开始工作,我一直遇到“找不到符号错误”或“双和int之间可能有损转换”等等。你能帮我看看下面的类和测试器代码出了什么问题?这只是我目前正在处理的代码的一部分。请随时向我提问,如果需要,我会尽力澄清我正在尝试做的事情。谢谢。

班级代码;

// method that sets the number of houses
    public void setAmountOfHouses(int amountOfHouses)
    {
        //System.out.println("Enter the amount of houses for sale: "); // prompt

        if (amountOfHouses > 0) // if the number of houses is valid
            this.amountOfHouses = amountOfHouses; // assign it to instance variable number of houses
        else
            System.out.println("Please add at least 1 house to database... ");
    }

    // method that returns the number of houses
    public int getAmountOfHouses()
    {
        return amountOfHouses;
    }

    // method that set the house price
    public void setHousePrice(int housePrice)
    {
        if(housePrice > 0)
        {
            this.housePrice = housePrice;
        }
        else 
        {
            System.out.println("Enter a valid house price ");
        }
    }

    // method that returns the house price
    public double getHousePrice()
    {
        return housePrice;
    }

    //method to calculate fees and taxes
    public void calculateFees(int housePrice)
    {
        if(housePrice > 0 && housePrice <= 100000)
        {
            housePriceWithTax = housePrice + tax0; // no tax 
            totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
            totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
        }
        else if(housePrice >= 100001 && housePrice <= 200000)
        {
                housePriceWithTax = (((housePrice - 100000) * stampDuty1) + housePrice) + tax0;
                totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
                totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
        }
        else if(housePrice >= 200001 && housePrice <= 300000)
        {
            housePriceWithTax = (((housePrice - 200000) * stampDuty2) + housePrice) + tax0 + tax1;
            totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
            totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
            }
        else if(housePrice >= 300001 && housePrice <= 400000)
        {
            housePriceWithTax = ((housePrice - 300000) * stampDuty3) + housePrice + tax0 + tax1 + tax2;
            totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
            totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
        }
        else if(housePrice >= 400001)
        {
            housePriceWithTax = (((housePrice - 400000) * stampDuty4) + housePrice) + tax0 + tax1 + tax2 + tax3;
            totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
            totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
        }
        else 
        {
            housePriceWithTax = (((housePrice - 400000) * stampDuty4) + housePrice) + tax0 + tax1 + tax2 + tax3 + tax4;
            totalAuctioneerFeeAmount = housePriceWithTax * auctioneerFee;
            totalHousePrice = housePriceWithTax + totalAuctioneerFeeAmount;
        }
        System.out.println("Base house price is: " + housePrice);
        System.out.println("Cost of house with tax added is: " + housePriceWithTax);
        System.out.println("Total auctioneer fee on this house is: " + totalAuctioneerFeeAmount);
        System.out.println("Total cost of house with stamp duty and fees added is: " + totalHousePrice);
        }
    }

测试人员代码;

// Entering the amount of houses
    System.out.println("\nEnter the amount of houses for sale: "); // prompt
    int amountOfHouses = input.nextInt(); // obtain from input
    client1.setAmountOfHouses(amountOfHouses);
    if(client1.getAmountOfHouses() > 0)
        System.out.println("Adding " + client1.getAmountOfHouses() + " houses to database..." );
    else
        System.out.println("Returning...");

    // setting the price of each house
    int counter = 0;
    do
    {
        System.out.println("\nEnter the price of each house for sale: ");
        int housePrice = input.nextInt();
        client1.setHousePrice(housePrice);
        System.out.println("\nAdding house price of " + client1.getHousePrice() + " to database");
        counter++;
    }
    while(counter < amountOfHouses);

    // calculating fees and taxes
    counter = 0;
    do
    {
        client1.calculateFees(client1.getHousePrice());
        counter++;
    }
    while(counter < amountOfHouses);
    }
}

0 个答案:

没有答案