Question 1. [20 marks in total]All questions in this section relate to the following classdefinition:/*SteamGame class represents a video game*/class SteamGame {private String name ;private int numDownloads ;private double price ;}a. (2 marks) Define getter methods for each of the instancevariables.
b. (2 marks) Define setter methods for the name and price instancevari-ables. You must include validation to make sure that the inputprice isnon-negative (not less than zero), and is less than 1000. Forexample, if theuser tries to set the price to -$50, the price should be recordedas $0.
c. (2 marks) Define a constructor with three parameters whichinitialises eachof the instance variables. You must include the validationmentioned in theprevious question, and numDownloads must not be less than zero.
d. (4 marks) Define a method called discount which decreases theprice bythe given percentage.public void discount ( int percent ) {// Complete the method}
e. (2 marks) Assuming that pubg represents an already instantiatedSteamGameobject, write a line of code which will put a 50% discount on thegame.
f. (4 marks) Define an instance method morePopular that when passedan-other SteamGame object, returns,• 1, if calling object’s number of downloads is more than parameterobject’s number of downloads.
Question 1. [20 marks in total] All questions in this section relate to the following class definition: /* SteamGame cla
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am