Lab 3
Lab 3
Statement
Exercise 1
Create the car class with a speed change, by installing, first of all, two methods returning nothing, but
allowing one to increment the speed and the other to decrement it. Then overload the speed
increment method, passing it as an argument the quantity of speed to add.
Exercise 2
Exercise 3
A.java, B.java and C.java files will not compile. Explain why.
A.java
public class A {
void A(int i) {
System.out.println("Hello");
}
public static void main(String[] args) {A unA = new A(5);}
}
B.java
class Test {
int a;
Test (int b) {a = b;}
}
public class B {
public static void main(String[] args) {
Test unTest = new Test();
}
}
C.java
class Test {
int a;
int c;
Test (int b) {a = b;}
static int donneC() {
return c;
}
}
public class C {
public static void main(String[] args)
{ Test unTest = new Test(5);}
}
Exercise 4
Create the constructor of the car class, initializing the speed to 0. Overload this constructor for cases
where we know the initial speed.
Exercise 5
Among the following attributes of the Renault Kangoo class, the version with all possible options,
separate those that you would declare as static: speed, number of passengers, maximum speed,
number of gears, tank capacity, age, power, price, color, number of doors.
Exercise 6
Create, in Java, a program containing a Point class, with its three coordinates in space (x,y,z), and which
can be initialized in three different ways (we know either x, or x and y, or x and y and z). Next, include
a translate() method in the class that is overloaded three times, also depending on which of the three
translation values are known.
Create two objects of the Point class and test whether the program works correctly when you translate
these points.