Product.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package p1;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title p1.Product
  6. * @description 商品类
  7. * @create 2026/7/20
  8. */
  9. public class Product {
  10. /**
  11. * 品牌
  12. */
  13. private String brand;
  14. /**
  15. * 名称
  16. */
  17. private String name;
  18. /**
  19. * 价格
  20. */
  21. private double price;
  22. /**
  23. * 数量
  24. */
  25. private int count;
  26. /**
  27. * 为商品品牌赋值
  28. * @param newBrand
  29. */
  30. public void setBrand(String brand){
  31. //如果 方法参数 使用的是brand(方法参数也属于局部变量) 和成员变量名相同,
  32. // 在当前方法中,按照就近原则,会都使用的是局部变量,而不是使用成员变量
  33. //所以,要么就为局部变量设置新的变量名。
  34. //要么就使用this关键字, 通过this关键字调用的变量是当前对象的成员变量。调用的方法是当前对象的成员方法。
  35. //this主要的作用就是区分同名的成员变量和局部变量。使用this调用的就一定是成员变量
  36. // 我 me 俺 寡人 孤 洒家
  37. this.brand=brand;
  38. }
  39. /**
  40. * 获取商品的品牌
  41. * @return
  42. */
  43. public String getBrand(){
  44. return brand;
  45. }
  46. public void setName(String name){
  47. this.name=name;
  48. }
  49. public String getName(){
  50. return this.name;
  51. }
  52. public double getPrice() {
  53. return price;
  54. }
  55. public void setPrice(double price) {
  56. this.price = price;
  57. }
  58. public int getCount() {
  59. return count;
  60. }
  61. public void setCount(int count) {
  62. this.count = count;
  63. }
  64. }