This commit is contained in:
Lola 2024-03-28 11:33:59 +01:00
commit 127427b305
9 changed files with 155 additions and 0 deletions

10
LAB1/.classpath Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
LAB1/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

17
LAB1/.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LAB1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=16

59
LAB1/src/Keyboard.java Normal file
View File

@ -0,0 +1,59 @@
import java.io.*;
/**
* Class : Keyboard
* Description : The class implements input methods for primitive types from the keyboard.
*/
public class Keyboard {
/**
* Return a String typed on keyboard
* @return : a string
*/
public String readString() {
String sChaine = null;
//System.out.println("Enter a value :");
try {
// read the value
BufferedReader brLecteur ;
brLecteur = new BufferedReader(new InputStreamReader(System.in));
sChaine = brLecteur.readLine();
}
catch (IOException ee) {
System.out.println("Error");
}
return sChaine; // return the string
}
/**
* Return an Integer typed on keyboard
* @return : an integer
*/
public int readInt() {
String sChaine = readString(); // call readString
// cast from string to int
return Integer.parseInt(sChaine.trim());
}
/**
* Return a float typed on keyboard
* @return : a float
*/
public float readFloat() {
String sChaine = readString();
// cast from string to float
return Float.parseFloat(sChaine.trim());
}
/**
* Return a double typed on keyboard
* @return : a double
*/
public double readDouble() {
String sChaine = readString();
// cast frome string to double
return Double.parseDouble(sChaine.trim());
}
}

15
LAB1/src/Main.java Normal file
View File

@ -0,0 +1,15 @@
public class Main {
public static void main(String[] args) {
//Robot robo = new Robot();
//robo.sayHello();
//robo.sayHello2("Lola");
// RobotCalculator robo = new RobotCalculator();
// robo.average(15.0,5.0);
// RobotCalculator b = new RobotCalculator();
// b.askUserForNbOfStudent();
}
}

9
LAB1/src/Robot.java Normal file
View File

@ -0,0 +1,9 @@
public class Robot {
public void sayHello() {
System.out.println("Hello");
}
public void sayHello2(String name) {
System.out.println("Hello "+ name);
}
}

View File

@ -0,0 +1,26 @@
public class RobotCalculator {
public double average(double grade1, double grade2) {
double avg = (grade1 + grade2)/2;
return avg;
}
public void askUserForNbOfStudent() {
System.out.println("Give me the number of student");
Keyboard input = new Keyboard();
int nStudents = input.readInt();
double sum = 0 ;
for(int i=1;i<=nStudents;i++) {
System.out.println("Give me the fisrt grade");
double grade1 = input.readDouble();
System.out.println("Give me the second grade");
double grade2 = input.readDouble();
RobotCalculator robo = new RobotCalculator();
double StudentAvg = robo.average(grade1,grade2);
sum = sum + StudentAvg ;
System.out.println(StudentAvg);
}
System.out.println(sum/nStudents);
}
}

4
LAB1/src/Test.java Normal file
View File

@ -0,0 +1,4 @@
public class Test {
}