Make a class Person to represent a person according to the following requirements: A person has two
Fantastic news! We've Found the answer you've been seeking!
Question:
- Make a class Person to represent a person according to the following requirements: A person has two attributes:
- id
- name.
- Add a constructer to initialize all the attributes to specific values.
- Add all setter and getter methods.
- Create a class Product to represent a product according to the following requirements:
A product has four attributes:
- a referencenumber(can't be changed)
- a price
- an owner (is a person)
- a shopName (is the same for all the products).
- Add a constructer without parameters to initialize all the attributes to default values (0 for numbers, "" for a string and null for object).
- Add a second constructer to initialize all the attributes to specific values. Use the keyword "this".
- Add the method changePrice that change the price of a product. The method must display an error message if the given price is negative.
- Add a static method changeShopName to change the shop name.
- Add all the getter methods. The method getOwner must return an owner.
- Make the class ProductTester with the main method. In this class do the following:
- Make a person p1. The person's name and id must be your name and your student Id.
- Make a product with the following information:
reference = 1.
price = a value from your choice.
owner = p1.
shopName = "SEU".
- Change the price of the product to your age.
- Change the shop name to your full name.
- Print all the information of the product.
Typical runs of the program
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date: