master
This commit is contained in:
23
src/lab1/Fuel.java
Normal file
23
src/lab1/Fuel.java
Normal file
@ -0,0 +1,23 @@
|
||||
package lab1;
|
||||
public class Fuel
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
double litre = 0;
|
||||
double distance = 0;
|
||||
|
||||
|
||||
System.out.println("Calculateur de conssomation d'essence.");
|
||||
|
||||
System.out.print("Veuillez entrer la conssomation moyenne de votre voiture : ");
|
||||
litre = Input.readDouble();
|
||||
|
||||
System.out.print("Veuillez entrer le nombre de kilom<6F>tre parcourus : ");
|
||||
distance = Input.readDouble();
|
||||
|
||||
double consso = 0;
|
||||
consso = litre * (distance/100);
|
||||
|
||||
System.out.println("Votre conssomation a été de " + consso + " litres d'essence");
|
||||
}
|
||||
}
|
74
src/lab1/Input.java
Normal file
74
src/lab1/Input.java
Normal file
@ -0,0 +1,74 @@
|
||||
package lab1;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The Class Input is here to enter data with the keyboard.<br>
|
||||
* The types below are supported by the Input class. <br><br>
|
||||
* - String <br> - Integer (int) <br> - Double (double) - Boolean (boolean) <br> - Character (char) <br> <br><br>
|
||||
* @see #readString()
|
||||
* @see #readInt()
|
||||
* @see #readDouble()
|
||||
* @see #readBoolean()
|
||||
* @see #readChar()
|
||||
*/
|
||||
public class Input
|
||||
{
|
||||
/**
|
||||
* Reads a String from the console.
|
||||
* @return The typed string
|
||||
* @see java.lang.String
|
||||
*/
|
||||
public static String readString()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {return stdin.readLine(); }
|
||||
catch (Exception ex) { return "";}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an Integer from the console.
|
||||
* @return The typed Integer or 0 if the typed Integer is invalid
|
||||
* @see java.lang.Integer
|
||||
*/
|
||||
public static int readInt()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Integer.parseInt(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Double from the console.
|
||||
* @return The typed Double or 0 if the typed Double is invalid
|
||||
* @see java.lang.Double
|
||||
*/
|
||||
public static double readDouble()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return Double.parseDouble(stdin.readLine()); }
|
||||
catch (Exception ex) { return 0; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a boolean from the console.
|
||||
* @return The typed boolean or false if the typed boolean is other than "true"
|
||||
*/
|
||||
public static boolean readBoolean()
|
||||
{
|
||||
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return (Boolean.valueOf(stdin.readLine())).booleanValue(); }
|
||||
catch (Exception ex) {return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a char from the console.
|
||||
* @return The typed char or the character 0 if the typed char is invalid
|
||||
*/
|
||||
public static char readChar()
|
||||
{
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try { return stdin.readLine().charAt(0); }
|
||||
catch (Exception ex) {return '\0'; }
|
||||
}
|
||||
}
|
17
src/lab1/MyProgram.java
Normal file
17
src/lab1/MyProgram.java
Normal file
@ -0,0 +1,17 @@
|
||||
package lab1;
|
||||
public class MyProgram {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Declaration de 2 variables
|
||||
int note1 = 3;
|
||||
int note2 = 5;
|
||||
|
||||
// Faire l'opération
|
||||
double theSum = note1 + note2;
|
||||
double average = theSum/2;
|
||||
|
||||
// Afficher le résultat
|
||||
System.out.print("La moyenne est égal à : ");
|
||||
System.out.println(average);
|
||||
}
|
||||
}
|
37
src/lab1/RoomCalc.java
Normal file
37
src/lab1/RoomCalc.java
Normal file
@ -0,0 +1,37 @@
|
||||
package lab1;
|
||||
public class RoomCalc
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
// Declares three variables to store the dimensions
|
||||
double width = 0;
|
||||
double height = 0;
|
||||
double length = 0;
|
||||
|
||||
/*
|
||||
* For each dimension, display a message,
|
||||
* gets the value from the user
|
||||
* and store the value in the corresponding variable
|
||||
*/
|
||||
System.out.println("Volume calculator, by Rémi Heredero");
|
||||
|
||||
System.out.print("Enter width (m) : ");
|
||||
width = Input.readDouble();
|
||||
|
||||
System.out.print("Enter length (m) : ");
|
||||
length = Input.readDouble();
|
||||
|
||||
System.out.print("Enter height (m) : ");
|
||||
height = Input.readDouble();
|
||||
|
||||
// Perform the computation
|
||||
double vol = 0;
|
||||
vol = width * length * height;
|
||||
|
||||
// Compute the volume and displays it
|
||||
System.out.println("The corresponding volume is " + vol + " m^3 big");
|
||||
System.out.println("The corresponding volume is " + vol/0.00454609 + " gallon");
|
||||
|
||||
System.out.println("Goodbye and thank you");
|
||||
}
|
||||
}
|
42
src/lab1/sphere.java
Normal file
42
src/lab1/sphere.java
Normal file
@ -0,0 +1,42 @@
|
||||
package lab1;
|
||||
public class sphere {
|
||||
public static void main(String args[])
|
||||
{
|
||||
double rayon = 0;
|
||||
double epaisseur = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.print("Veuillez entrer le rayon de la sphère en cm : ");
|
||||
rayon = Input.readDouble();
|
||||
|
||||
System.out.print("Veuillez entrer l'épaisseur de la sphère : ");
|
||||
epaisseur = Input.readDouble();
|
||||
|
||||
double rayonInt = rayon - epaisseur;
|
||||
double volume = 0;
|
||||
double volumeInt = 0;
|
||||
volume = (4*Math.PI*rayon*rayon*rayon)/3;
|
||||
volumeInt = (4*Math.PI*rayonInt*rayonInt*rayonInt)/3;
|
||||
|
||||
System.out.println("Le volume total est de " + volume + " cm3");
|
||||
|
||||
double densite = 0;
|
||||
System.out.print("Veuillez entrer la densité de la matière en g/cm3: ");
|
||||
densite = Input.readDouble();
|
||||
|
||||
double poid = 0;
|
||||
poid = densite*(volume-volumeInt);
|
||||
|
||||
System.out.print("La densité total est de " + poid/volume + " => ");
|
||||
|
||||
if(poid/volume < 1) {
|
||||
System.out.println("L'object flotte");
|
||||
} else {
|
||||
System.out.println("L'object ne flotte pas");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
24
src/lab1/swap.java
Normal file
24
src/lab1/swap.java
Normal file
@ -0,0 +1,24 @@
|
||||
package lab1;
|
||||
|
||||
public class swap
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a = 12;
|
||||
int b = 5;
|
||||
|
||||
|
||||
System.out.println("A: "+a);
|
||||
System.out.println("B: "+b);
|
||||
|
||||
System.out.println("swap...");
|
||||
|
||||
int swap = a;
|
||||
a=b;
|
||||
b=swap;
|
||||
|
||||
System.out.println("A: "+a);
|
||||
System.out.println("B: "+b);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user