to create a good structured application that is created using separated components and separated I mean logically physically, you need to think of each component as an independent side, which means that the transformation logic must be separated from the input logic (by input, I mean getting input data)
, Scanner, , , -. , (IN) ( if, - ) ,
, , .
ex: Conversion
public double convert(String newTypeOne, String newTypeTwo, double newValueOne){
if (newTypeOne.equalsIgnoreCase("mm") && newTypeTwo.equalsIgnoreCase("cm")){
return mmToCm(newValueOne);
}else if (...){
return ...;
}
:
: ... and so on
}
, , , , Scanner .
main :
public static void main(String [] args){
Conversion convertThisVal = new Conversion();
Scanner typeOne = new Scanner(System.in);
Scanner typeTwo = new Scanner(System.in);
Scanner valueOne = new Scanner(System.in);
System.out.println("Convert From: ");
String newTypeOne = typeOne.next();
System.out.println("To: ");
String newTypeTwo = typeTwo.next();
System.out.println("Enter the values!");
double newValueOne = valueOne.nextDouble();
System.out.println("cm:" + convertThisVal.convert(newTypeOne,newTypeTwo, newValueOne ));
}
convert(), , .
, , , .
, , ( , - ..)
, .