0% found this document useful (0 votes)
12 views

OOP Ass 1 Classes and Objects

The document outlines programming tasks involving the creation of classes in Java, including Student and Account classes with various methods for setting details, calculating totals, and displaying information. It also includes advanced tasks for creating Holiday and Movie classes with constructors and methods for comparison and filtering. The exercises aim to enhance understanding of classes and objects in Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

OOP Ass 1 Classes and Objects

The document outlines programming tasks involving the creation of classes in Java, including Student and Account classes with various methods for setting details, calculating totals, and displaying information. It also includes advanced tasks for creating Holiday and Movie classes with constructors and methods for comparison and filtering. The exercises aim to enhance understanding of classes and objects in Java programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Basic

1. Write a program which creates a class Student with the following Data Members rollNum,
studName, mark1, mark2, mark3, totalMarks
Methods
setStudDetails() – which sets the values to all the data members except totalMarks.
calculateTotal() - which calculate the totalMarks
displayStudDetails() – which displays rollNum, studName and totalMarks
Create a class StudentDemo to test the functionality of Student class

2. Create a class Account with accountNumber, custName, balance and


interest rate. create method calculateInterest() which will calculate interest and
add to balance. create a method to displayAccountDetails()

3. Create a class Account with the attributes accountNo, custName, accountBalance


and
methods
setAccountDetails() which set the values to these attributes.
withdraw() which subtracts the given amount from the available balance
deposit() which adds a given amount to the available balance and
dispAccountDetails() which displays accountNo, custName,
accountBalance.
Create a class Main1 which contains the main() method to test the functionality of Account
class.

4. Create a class Student with attributes rollNo, Name, marks1, marks2, marks3.
create a method getTop3Student() which accepts a list of Students and returns an array of 3
top students with the highest percentage.

Advanced
Practice Problems: Classes and Objects (Chapters 5 and 6)

1) The Java class called Holiday is stated below. An object of class Holiday
represents a holiday during the year. This class has three instance variables:

● name, which is a String representing the name of the holiday

● day, which is an int representing the day of the month of the holiday

● month, which is a String representing the month the holiday is in

public t

a) Write a constructor for the class Holiday, which takes a String representing the
name, an int representing the day, and a String representing 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 true if they have the same month, and false if they do not.

c) Write a method avgDate which takes an array of base type Holiday as its
argument, and returns a double that is the average of the day variables in the
Holiday instances in the array. You may assume that the array is full (i.e. does not have
any null entries).

2) The class Movie is stated below. An instance of class Movie represents a film. This class
has the following three class variables:

● title, which is a String representing the title of the movie

● studio, which is a String representing the studio that made the movie

● rating, which is a String representing the rating of the movie (1 star, 2 star etc)

public class Movie {


private String title;

private String studio;

private String rating;

a) Write a constructor for the class Movie, which takes a String representing the title of
the movie, a String representing the studio, and a String representing the rating as its
arguments, and sets the respective class variables to these values.

b) Write a second constructor for the class Movie, which takes a String representing the
title of the movie and a String representing the studio as its arguments, and sets the
respective class variables to these values, while the class variable rating is set to "5 star".

c) Write a method get5StarMovies, which takes an array of base type Movie as its
argument, and returns a new array of only those movies in the input array with a rating of "5
star". You may assume the input array is full of Movie instances. The returned array need not
be full.

You might also like