Anonymous 发表于 2022-12-19 19:36:04

求助,编写这个系统,运行结果相同(急)!

本帖最后由 匿名 于 2022-12-20 18:40 编辑

Simulate one invoice system
1.Implement a class called Item with the following specification:
An attribute/field called name to store the name of the item
An attribute/field called price that stores the price in pounds
An attribute called origin that stores the place of the item’s origin
A constructor with two parameters (the name of the item and the price) that initialises origin to null
Getter methods (getName, getPrice, getOrigin) and setter methods (setName, setPrice, setOrigin) for the three attributes above
A method to display the name, price and origin of the item.

2.Create in the main program a list called bill that stores items
3.Write code that asks the user to input the name, price and origin of item then create instance of the class Item and add them to list bill until user input other characters (not “YES”).When the user enters "YES", the program can continue adding item.
4.Print an invoice by displaying the items bought with their prices and the total payment.
For example:
RESTART:F:\teach\2022Problem Solving and Programming\asse
Add item to invoice("YES" to continue, others to stop)? YES
Input name:a
Input price:1
Input origin:aa
Add item to invoice("YES"to continue, others to stop)? YES
Input name:b
Input price:2
Input origin:bb
Add item to invoice("YES" to continue, others to stop)?YES
Input name:c
Input price:3
Input origin:cc
Add item to invoice("YES" to continue, others to stop)? stop
name: a price: 1.0 origin: aa
name: b price: 2.0 origin: bb
name: c price: 3.0 origin: cc Total price: 6.0
>>>



(Hint: Do not access the attributes of the class directly, please use getter methods.)
页: [1]
查看完整版本: 求助,编写这个系统,运行结果相同(急)!