CS342 Lab1
CS342 Lab1
1) Define a Person class containing two private attributes: lastname, firstname. Provide
this class with a constructor allowing the initialization of its attributes and a method that
displays the last name and first name of a person: void displaysPerson ().
2) Define a Customer class inheriting from the Person class and having a private
attribute: numidentity. Provide this class with a constructor allowing you to create a
customer from their last name, first name and identity card number and a method:
• void displaysCustomer () which displays the lastname, firstname and
numidentity of a customer.
3) Define a Owner class inheriting from the Person class and having two private
attributes: name of the video club (nameclub), address of the club (adrclub). Provide
this class with a constructor allowing to create a landlord from his name, his first name,
the name of his video club, the address of his club and a method:
void displaysOwner() who displays the name, first name, last name and address of his
video club.
4) Define a Date class containing three private attributes day, month, year. Provide this
class with a constructor allowing the initialization of its attributes.
5) Define a Film class such that any film is defined by its title, genre, identifier and date
of first transmission (datetrans). Provide this class with a constructor allowing the
initialization of its attributes and a method (void displayFilm ()) which displays the
characteristics of a movie.
6) Define an Organize class which contains private attributes: tabfilm which will be an
array of films, nbfilm (indicates the number of films in the tabfilm array) and maxfilm
(indicates the size of the array).
This class will contain methods for.
• Add films: void add (Film f) the film is added at the end of the table (tabfilm), if
the table is full it displays an error message. Display the list of films: void
displaysListFilm ().
1
• Search for a movie by its title: void searchesMovie (String title) and displays its
characteristics, otherwise it displays an error message.
7) Create a Test class in order to test all the created classes.
Exercice 2:
Exercice 3:
2
A point is characterized by its abscissa (of double type) and its ordinate (of double
type).
Questions:
1) Define the Point, Shape, Circle and Rectangle classes
2) Write a small application as a TestForm class that creates an object of each
geometric shape and displays their area and perimeter.
Exercice 4:
We ask to repeat the exercise 2, assuming that Shape is an interface. We also assume
that the Circle class has a constructor with the following prototype:
public Circle (double, Point)
Questions:
1) Define the Shape interface
2) Define a Displayable interface including a void display () method
3) Define the Point class which implements the Displayable interface
4) Define the Circle and Rectangle classes which implement Shape and Displayable
5) Write a small application in the form of a TestFormInterface class which allows you
to declare an array (TabObjet []) of 3 Displayable type inputs. To create: a Point object
and put its reference in the first entry, a Rectangle object and put its reference in the
second entry and a Circle object and put its reference in the third entry. The circle object
uses the point of the first entry in the array as the center. Display the characteristics of
all the objects that are in the table.
Exercice 4:
3
5) Add the TestShelf class which allows you to test all the classes.
Exercice 5:
Modify the program by initializing y at 0. Recompile and re-run the program. What’s
going on? Did the program end well? Consider a solution to this problem:
1. Using a predefined exception class.
2. Using a predefined exception class with a custom message.
3. Using your own exception class (give a meaningful name and message).
Exercice 6:
What does the CalculMoyennelanced program give in the following three cases:
• String tab[] = {"14", "12", "13", "16", "18", "15"};
• String tab[] = {"x", "2", "-1", "30", "18"};
• String tab[] = {"x", "-3", "2.3"};
if(nbNotes == 0)
throw new ExceptionRien();
return (int)sum/nbNotes;
}
Exercice 7: