Lecturer Leila Lab Java
Lecturer Leila Lab Java
Room 346
Time: 9:00
First exercise
Database contains data, so to prepare you for dealing with this we will take this
exercise.
This class intend to help students to understand Java. The main goal here is to find
the period between the two things, how you going to get the input, insert day,
month, and year of your birthday. You use this data to calculate the timing
between the two dates.
Class used is local date, extend only one class, but implement number of interfaces.
Go back to NetBeans and create a project, if you have (And) use it, I will use simple
java application
Do the usual labs and then lab2o2 and I will name it lab2.
Pay attention, it gives you the full path to how to get to this file.
Looks like Maven is not set up, so I will use another framework.
To find the differences between the two, we can use this fastperiod and the method
used will be between and it will give us the time that laps between the two
dates.
Line 34 replaces all this, if you do not want to hard code you can use the methods
Two local dates: the starting and the other date and create a object of class
It is only one way of doing it, any combination is also ok, if you want to use objects.
Last time we did the guessing, 2b, and 2c is very similar activity to 2b.
Class animal (super class) and then sub-classes such as mammals, pets …
Copy the code provide, this class literally is just used for testing
When you go back to the handout so you can create a virtual farm and use a certain
number of cows:
3 anger cows
We start with the two string methods and again that goes to the cow class, right click
insert code, find the two strings, and add method
It will not exist really angry string, so we can build the string ourselves and then if the
cow is really angry we can extend the result with additional information which is to
give string representation of the object, in this case we do not have, so it is just to
run and test it.
Let’s reduce the amount of milk, there is not a explicit method to define the amount
of the milk:
We have the printout, but we have not really implemented the method, so we need to
change the month, now we have a printout to say that the cow is really angry
If you go back to the handout, check the information there to implement this
functionality you need to be inside the method.
If the cow is angry, it means the amount of milk is 0, you can either check the milk or
say …
Basic behaviour, but check milking method, it is where can have problems, when
someone try to milk the cow it can unease the other animals.
New class java, class named farm and it will be at the same package.
The farm itself is a collection of cow, you decide what to have in there an array list or
I will be more descriptive here; a list of objects and you can put them in a array list
You can specify the inicial capacity and that will create an array list, then we can add
two string methods after and then we can go and create a farm: myFarm, I will print
because at the moment we do not have a method to enter a cow to this farm, as we
can see it is empty.
Let’s get a method that can store a cow and add it to the farm:
Cow really angry we increase that, be careful, because a really angry cow can calm
down after being fed.
And if this number goes down, all happening in the cow class, we can implement this
on two ways
In the farm:
Getting cow as index 1 and feeding it
Generate a number and using that to initiate the activity
Pick the cow in the farm always a different cow, in the feed method you will be
doing random generation
( Leila started to create the class meetings, you can go online and book a slot. Also
used as attendance, so if you are in, go online get the attachments and I will know
that you were in for the class.)
The program terminates when there are more than 3 angry cows, to terminate the
program you can use loop.
If it is equal to 0 than you can give two cows with same name, compare the
among of milk.
Comparing methods.
Comparable objects.