Last active
March 22, 2017 16:33
-
-
Save mattiaferigutti/cea577a984012fe7513145dfaaf011f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* Created by Mattia on 22/03/2017. | |
*/ | |
public class MainTriangolo | |
{ | |
public static void main(String args[]) | |
{ | |
int a, b, c; | |
Scanner scan = new Scanner(System.in); //scanner Oggetto tramite il quale prendere i valori | |
System.out.println("inserisci a"); | |
a = scan.nextInt(); //nextInt() metodo tramite il quale trasformare il parametro in int | |
System.out.println("inserisci b"); | |
b = scan.nextInt(); | |
System.out.println("inserisci c"); | |
c = scan.nextInt(); | |
Triangolo oggetto = new Triangolo(a, b, c); //istanzio oggetto della classe Triangolo e tramite "()" inserisco i valori del costruttore | |
//controllo valori inseriti | |
if (a!=0 && b!=0 && c!=0) | |
oggetto.Verifica(); //richiamo il metodo Verifica della classe Triangolo | |
else System.out.println("Inserisci valori accettabili"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Mattia on 22/03/2017. | |
*/ | |
public class Triangolo | |
{ | |
private int a; //private: definisco che le variabili sono visibili solo all'interno della classe stessa | |
private int b; | |
private int c; | |
public Triangolo(int a, int b, int c) //costruttore: inizializzo le variabili | |
{ | |
this.a = a; | |
this.b = b; | |
this.c = c; | |
} | |
public void Verifica() | |
{ | |
if ((a+b)>c && (b+c)>a && (a+c)>b) | |
{ | |
if (a!=b && b!=c && c!=a) | |
System.out.println("E' scaleno"); | |
else if (a==b && b==c && c==a) | |
System.out.println("E' equilatero"); | |
else System.out.println("E' isoscele"); | |
} | |
else System.out.println("Errore di inserimento dati"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment