Question 1. [20 marks in total] All questions in this section relate to the following class definition: /* SteamGame cla

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Question 1. [20 marks in total] All questions in this section relate to the following class definition: /* SteamGame cla

Post by answerhappygod »

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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply