Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Galtier Virginie
JavaBootcamp
Commits
49460c11
Commit
49460c11
authored
Sep 12, 2022
by
Galtier Virginie
Browse files
updated version of the public repo
parent
f539a03b
Changes
86
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
0 → 100644
View file @
49460c11
image
:
maven:latest
stages
:
-
deploy
pages
:
stage
:
deploy
tags
:
-
docker
script
:
-
/usr/bin/mvn clean package javadoc::javadoc -Dshow=private -f Game/pom.xml
-
mkdir -p public
-
cp -r Game/target/apidocs/* public
-
ls -al public/*
artifacts
:
paths
:
-
public/
Code/pom.xml
0 → 100644
View file @
49460c11
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
fr.centralesupelec.galtier
</groupId>
<artifactId>
bootcamp
</artifactId>
<version>
1
</version>
</project>
\ No newline at end of file
Code/src/main/java/Rectangle.java
0 → 100644
View file @
49460c11
public
class
Rectangle
{
// attributes:
double
width
;
double
length
;
static
int
nbRectangles
=
0
;
// constructor:
Rectangle
(
double
w
,
double
l
)
{
width
=
w
;
length
=
l
;
nbRectangles
++;
}
// methods that read attributes:
double
getArea
()
{
return
(
length
*
width
);
}
double
getPerimeter
()
{
return
2
*
(
length
+
width
);
}
// method that changes attributes:
void
resize
(
double
coefficient
)
{
length
=
length
*
coefficient
;
width
=
width
*
coefficient
;
}
// displayer:
void
printDescription
()
{
System
.
out
.
println
(
"width = "
+
width
+
", length = "
+
length
);
}
}
Code/src/main/java/bootcamp/part1/_01_helloWorld/HelloWorld.java
0 → 100644
View file @
49460c11
/**
* First example
*/
package
bootcamp.part1._01_helloWorld
;
public
class
HelloWorld
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
);
}
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld2.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld2
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
);
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld3.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld3
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
)
}
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld4.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld4
{
public
static
void
main
(
String
[]
args
)
{
system
.
out
.
println
(
"Hello world!"
);
}
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld5.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld5
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
display
(
"Hello world!"
);
}
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld6.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld6
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
'
Hello
world
!
'
);
}
}
Code/src/main/java/bootcamp/part1/_02_helloWorld/bugged/HelloWorld7.java
0 → 100644
View file @
49460c11
/**
* Read this program and try to find the problem.
* Attempt to execute the program and observe the error message.
* Correct the problem so the program executes and displays "Hello world!".
*/
package
bootcamp.part1._02_helloWorld.bugged
;
public
class
HelloWorld7
{
public
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello world!"
);
}
}
Code/src/main/java/bootcamp/part1/_03_helloWorldAlt/HelloWorld.java
0 → 100644
View file @
49460c11
/**
* For now, keep the 'main' method minimalist
* and write all the code in the constructor
* as in the following example.
*/
package
bootcamp.part1._03_helloWorldAlt
;
public
class
HelloWorld
{
public
static
void
main
(
String
[]
args
)
{
new
HelloWorld
();
}
public
HelloWorld
()
{
System
.
out
.
println
(
"Hello world!"
);
}
}
Code/src/main/java/bootcamp/part1/_04_variables/PrimitiveVarDemo.java
0 → 100644
View file @
49460c11
package
bootcamp.part1._04_variables
;
public
class
PrimitiveVarDemo
{
public
static
void
main
(
String
[]
args
)
{
new
PrimitiveVarDemo
();
}
public
PrimitiveVarDemo
()
{
int
nb
;
// declare variable type and name
nb
=
3
;
// assign value ("affectation" en français)
int
n
=
4
;
// declaration and value assignment in one line
boolean
isGood
=
false
;
// !!! "False" in Python, but "false" in Java
char
a
=
'e'
;
char
c
;
c
=
a
;
System
.
out
.
println
(
c
);
// Which instructions are correct?
// Uncomment each line, one at a time to find out.
// c = 'a';
// c = a;
// c = '\n';
// c = null;
// c = "a";
// c = '';
// c = b;
// example of runtime error
int
q
=
3
/
0
;
}
}
Code/src/main/java/bootcamp/part1/_05_methods/Exercise1.java
0 → 100644
View file @
49460c11
/**
* Find the 3 problems in this code.
*/
package
bootcamp.part1._05_methods
;
class
Exercise1
{
public
static
void
main
(
String
[]
args
)
{
new
Exercise1
();
}
Exercise1
()
{
char
s
=
sum
(
1
,
2
);
System
.
out
.
print
(
s
);
System
.
out
.
print
(
result
);
}
int
sum
(
int
a
,
int
b
)
{
int
result
=
a
+
b
;
return
result
;
System
.
out
.
print
(
result
);
}
}
Code/src/main/java/bootcamp/part1/_05_methods/Exercise2.java
0 → 100644
View file @
49460c11
/**
* Write a method atLeastOneFalse that takes 3 boolean values as parameters
* and returns true if at least one of them is false, and false otherwise.
* (Use the Java Memento to learn about boolean operations syntax.)
*/
package
bootcamp.part1._05_methods
;
public
class
Exercise2
{
public
static
void
main
(
String
[]
args
)
{
new
Exercise2
();
}
public
Exercise2
()
{
System
.
out
.
println
(
atLeastOneFalse
(
true
,
true
,
true
));
// expected return: false
System
.
out
.
println
(
atLeastOneFalse
(
true
,
true
,
false
));
// expected return: true
System
.
out
.
println
(
atLeastOneFalse
(
false
,
true
,
false
));
// expected return: true
}
}
Code/src/main/java/bootcamp/part1/_05_methods/NoParamNoReturn.java
0 → 100644
View file @
49460c11
/**
* Write a hello method that doesn't take parameters and
* doesn't return a result but simply displays "hello".
*/
package
bootcamp.part1._05_methods
;
public
class
NoParamNoReturn
{
public
static
void
main
(
String
[]
args
)
{
new
NoParamNoReturn
();
}
public
NoParamNoReturn
()
{
hello
();
}
// write the hello method here
}
Code/src/main/java/bootcamp/part1/_05_methods/WithParamNoReturn.java
0 → 100644
View file @
49460c11
/**
* Write a method displayProduct that takes 2 integer values (int) as parameters
* and displays their product using the following format:
* 2 * 3 = 6 (first operand, space character, "*", space character, "=", space, result)
*/
package
bootcamp.part1._05_methods
;
public
class
WithParamNoReturn
{
public
static
void
main
(
String
[]
args
)
{
new
WithParamNoReturn
();
}
public
WithParamNoReturn
()
{
displayProduct
(
2
,
3
);
}
}
Code/src/main/java/bootcamp/part1/_06_cast/HelloWorld.java
0 → 100644
View file @
49460c11
/**
* Add a cast where needed.
* Observe the display values.
*/
package
bootcamp.part1._06_cast
;
public
class
HelloWorld
{
public
static
void
main
(
String
[]
args
)
{
new
HelloWorld
();
}
public
HelloWorld
()
{
// int is double
int
i
=
3
;
double
d
=
i
;
System
.
out
.
println
(
"i = "
+
i
+
"\t d = "
+
d
);
// double is not int
double
pi
=
3.14
;
int
n
=
pi
;
d
=
n
;
System
.
out
.
println
(
"pi="
+
pi
+
" n="
+
n
+
" d="
+
d
);
}
}
Code/src/main/java/bootcamp/part1/_07_conditional/FactorialExercise.java
0 → 100644
View file @
49460c11
/**
* Write a recursive method to compute the factorial of an integer given as parameter.
*/
package
bootcamp.part1._07_conditional
;
public
class
FactorialExercise
{
public
static
void
main
(
String
[]
args
)
{
new
FactorialExercise
();
}
public
FactorialExercise
()
{
System
.
out
.
println
(
factorial
(
0
));
// expected result: 1
System
.
out
.
println
(
factorial
(
1
));
// expected result: 1
System
.
out
.
println
(
factorial
(
5
));
// expected result: 120
System
.
out
.
println
(
factorial
(
12
));
// expected result: 479,001,600
}
int
factorial
(
int
n
)
{
return
n
*
factorial
(
n
-
1
);
}
}
Code/src/main/java/bootcamp/part1/_07_conditional/RideExercise.java
0 → 100644
View file @
49460c11
/**
* The fare to a ride depends on the membership and age of the rider:
* non-members pay a price equal to their age, while members get 10% off.
* Write a method `double getFare(boolean isMember, int age)` to compute the fare.
*/
package
bootcamp.part1._07_conditional
;
public
class
RideExercise
{
public
static
void
main
(
String
[]
args
)
{
new
RideExercise
();
}
public
RideExercise
()
{
System
.
out
.
println
(
getFare
(
false
,
9
));
// expected result: 9
System
.
out
.
println
(
getFare
(
true
,
9
));
// expected result: 8.1
System
.
out
.
println
(
getFare
(
true
,
5
));
// expected result: 4.5
}
}
Code/src/main/java/bootcamp/part1/_08_loops/IterativeFactorialExercise.java
0 → 100644
View file @
49460c11
/**
* Replace the "for" loop of this iterative method by a "while" loop.
*/
package
bootcamp.part1._08_loops
;
public
class
IterativeFactorialExercise
{
public
static
void
main
(
String
[]
args
)
{
new
IterativeFactorialExercise
();
}
public
IterativeFactorialExercise
()
{
System
.
out
.
println
(
factorial
(
0
));
// expected result: 1
System
.
out
.
println
(
factorial
(
1
));
// expected result: 1
System
.
out
.
println
(
factorial
(
5
));
// expected result: 120
System
.
out
.
println
(
factorial
(
12
));
// expected result: 479,001,600
}
int
factorial
(
int
n
)
{
int
f
=
1
;
for
(
int
i
=
1
;
i
<=
n
;
i
++)
{
f
=
f
*
i
;
}
return
f
;
}
}
Prev
1
2
3
4
5
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment