Question: Practice Problems: Classes and Objects (Chapters 5 and 6) 1) The Java class called Holidayis started below. An object of class Holidayrepresents a holiday during
Practice Problems: Classes and Objects (Chapters 5 and 6)
1) The Java class called Holidayis started below. An object of class Holidayrepresents a holiday during the year. This class has three instance variables:
? name,whichisaStringrepresentingthenameoftheholiday
? day,whichisanintrepresentingthedayofthemonthoftheholiday ? month,whichisaStringrepresentingthemonththeholidayisin
public class Holiday { private String name;
private int day; private String month;
// your code goes here }
a) Write a constructor for the class Holiday, which takes a Stringrepresenting the name, an intrepresenting the day, and a Stringrepresenting the month as its arguments, and sets the class variables to these values.
b) Write a method inSameMonth, which compares two instances of the class Holiday,and returns the Boolean value trueif they have the same month, and falseif they do not.
c) Write a method avgDatewhich takes an array of base type Holidayas its argument, and returnsadoublethat istheaverageofthedayvariablesintheHolidayinstancesinthe array. You may assume that the array is full (i.e. does not have any null entries).
d) Write a piece of code that creates a Holidayinstance with the name Independence Day, with the day 4, and with the month July.
2) The class Movie is started below. An instance of class Movie represents a film. This class has the following three class variables:
? title,whichisaStringrepresentingthetitleofthemovie
? studio,whichisaStringrepresentingthestudiothatmadethemovie
? rating,whichisaStringrepresentingtheratingofthemovie(i.e.PG13,R,etc)
public class Movie { private String title; private String studio; private String rating;
// your code goes here }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
