为了账号安全,请及时绑定邮箱和手机立即绑定

方法字符串和编译器问题发票

方法字符串和编译器问题发票

慕丝7291255 2023-03-23 16:38:18
这就是我想要做的    Making·a·new·object·of·class·Invoice:↵Enter ·the·part·number:32-RJK-45↵Enter ·the·part·description:Phillips-Screw↵Enter ·the·Quantity·of·Items:20↵Enter· the·Price·Per·Item·with·cents·in·decimals:↵4.50↵↵ Invoice·price·and·amount·together:↵我尝试以多种方式使用编译器,使用字符串、双精度数和整数作为数量。这是我的发票页package week2chapter3;public class Invoice {    private String partNumber; // instance variable    private String partDescription; // instance variable    private double priceperitem; // double va1rible    private int itemBeingPurchesed;// used to total    private double invoiceAmount;// double that adds invoice amount    // Part Number    public Invoice (String partNumber,String partDescription,double priceperitem,            int itemBeingPurchesed,double invoiceAmount)     {this.partNumber = partNumber;// assign it to instance variable name     // method to get the part number    }    {this.partDescription = partDescription;// assign it to instance variable name     // method to get the part number    }    // Part Price    // validate that the priceperitem is greater than 0.0; if it is not,    // instance variable priceperitem keeps its default initial value of 0.0    public void setpriceperitem(double priceperitem) {        if (priceperitem > 0.0) {// if the balance is valid            this.priceperitem = priceperitem; // assign it to instance variable balance        }    }我收到几个错误。当我修复一个问题时,我得到未定义的构造函数,当我修复它时,我在我的源页面中得到一个错误,当我修复这些问题时,我得到格式错误。现在 partnumber 在测试页上被读取为错误,而 partDescription 被读取为未定义。
查看完整描述

1 回答

?
芜湖不芜

TA贡献1796条经验 获得超7个赞

这修复了您代码中的“错误”,但您的代码无法理解,我无法为您提供更多帮助。


    public class getInvoiceAmount { public static void main(String[] args) {


    Invoice invoice1 = new Invoice();

    Invoice invoice2 = new Invoice();

    Invoice invoice3 = new Invoice();

    Invoice invoice4 = new Invoice();

    // display initial balance of each object


    System.out.printf("Part number is: %s\n", invoice1.getpartNumber());

    System.out.printf("Part description: %s\n", invoice2.getpartDescription());

    System.out.printf("Part price: %.2f\n", invoice3.getpriceperitem());

    System.out.printf("Part number is: %d\n", invoice4.getitemBeingPurchesed());


    // create a Scanner to obtain input from the command window

    Scanner input = new Scanner(System.in);



    System.out.print("Enter the Part number:"); // prompt

    String partNumber = input.nextLine(); // obtain user input

    invoice1.setPartNumber( partNumber);


    System.out.print("Enter the part description:"); // prompt

    String partDescription = input.nextLine(); // obtain user input


    System.out.print("Enter the quantity of items :"); // prompt

    int itemBeingPurchesed = input.nextInt(); // obtain user input


    System.out.print("Enter the pric per item·with cents in decimalse:"); // prompt

    double priceperitem = input.nextDouble(); // obtain user input


    System.out.printf("Toatal for items: %.2f\n", invoice1.getinvoiceAmount());


    }

}



class Invoice {


    private String partNumber; // instance variable

    private String partDescription; // instance variable

    private double priceperitem; // double va1rible

    private int itemBeingPurchesed;// used to total

    private double invoiceAmount;// double that adds invoice amount



    public Invoice(){


    }

    // Part Number

    public Invoice (String partNumber,String partDescription,double priceperitem,

            int itemBeingPurchesed,double invoiceAmount)


    {this.partNumber = partNumber;// assign it to instance variable name

     // method to get the part number

    }


    {this.partDescription = partDescription;// assign it to instance variable name

     // method to get the part number

    }


    // Part Price

    // validate that the priceperitem is greater than 0.0; if it is not,

    // instance variable priceperitem keeps its default initial value of 0.0

    public void setpriceperitem(double priceperitem) {

        if (priceperitem > 0.0) {// if the balance is valid

            this.priceperitem = priceperitem; // assign it to instance variable balance

        }

    }


    // Item purchased

    // validate that the itemBeingPurchesed is greater than 0; if it is not,

    // instance variable itemBeingPurchesed keeps its default initial value of 0

    public void setitemBeingPurchesed(int itemBeingPurchesed) {

        if (itemBeingPurchesed > 0) {// if the balance is valid

            this.itemBeingPurchesed = itemBeingPurchesed;// assign it to instance variable balance

        }

    }


    // getInvoiceAmount multiply the total if nothing or negative it sets to 0

    public void invoiceAmount(double invoiceAmount) {

        if (invoiceAmount > 0) {// if the balance is valid

            invoiceAmount = itemBeingPurchesed * priceperitem; // assign it to instance variable balance

        }

    }


    public void setPartNumber(String part_number){

        partNumber = part_number;

    }


    // method that returns the partDescription

    public String getpartNumber() {

        return partNumber;

    }


    // method that returns the partDescription

    public String getpartDescription() {

        return partDescription;

    }


    // method returns the account priceperitem

    public double getpriceperitem() {

        return priceperitem;

    }


    public int getitemBeingPurchesed() {

        return itemBeingPurchesed;


    }


    // method returns the account priceperitem

    public double getinvoiceAmount() {

        return invoiceAmount;

    }

}



查看完整回答
反对 回复 2023-03-23
  • 1 回答
  • 0 关注
  • 56 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信