Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class ProblemaTramos{
- public static void main(String[] args) throws java.io.IOException{
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- PrintStream out = System.out;
- int numTramo = 0, costoTotal = 0, longCarretera = 0,
- tramoMayor = 0, tramoMenor = 0, numTramoMayor = 0, numTramoMenor = 0,
- anchoTramo, difNivelTramo, costoTramo, longTramo, material, costoMaterial,
- x1, y1, x2, y2;
- float relacInclinacion;
- String clasificacion = "";
- boolean procesar;
- out.println("******************************");
- out.println("* Tramos v1.0 *");
- out.println("* Por Ernesto V. y Julio M. *");
- out.println("******************************");
- out.println();
- out.println("Introduzca x1:");
- x1 = Integer.parseInt(in.readLine());
- out.println("Introduzca y1:");
- y1 = Integer.parseInt(in.readLine());
- out.println("Introduzca x2:");
- x2 = Integer.parseInt(in.readLine());
- out.println("Introduzca y2:");
- y2 = Integer.parseInt(in.readLine());
- do{
- procesar = false;
- out.println("Introduzca el ancho del tramo:");
- anchoTramo = Integer.parseInt(in.readLine());
- out.println("Introduzca la diferencia de nivel del tramo:");
- difNivelTramo = Integer.parseInt(in.readLine());
- out.println("Introduzca el material del tramo:");
- out.println("(0: material selecto, 1: adoquin, 2: asfalto)");
- material = Integer.parseInt(in.readLine());
- longTramo = (int) Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2)) * 1000;
- relacInclinacion = (float) difNivelTramo/longTramo;
- if(relacInclinacion >= 0 && relacInclinacion <= 0.3){
- if(relacInclinacion >= 0.05){
- procesar = true;
- clasificacion = "suave";
- }else if(relacInclinacion <= 0.2){
- procesar = true;
- clasificacion = "moderada";
- }else if(relacInclinacion <= 30 && longTramo <= 1000){
- procesar = true;
- clasificacion = "levemente fuerte";
- }
- }
- switch(material){
- case 0:
- costoMaterial = 4000;
- break;
- case 1:
- costoMaterial = 6000;
- break;
- case 2:
- costoMaterial = 17000;
- break;
- default:
- costoMaterial = 0;
- procesar = false;
- }
- if(procesar){
- numTramo++;
- x1 = x2;
- y1 = y2;
- costoTramo = anchoTramo*longTramo*costoMaterial;
- costoTotal += costoTramo;
- longCarretera += longTramo;
- if(longTramo > tramoMayor){
- numTramoMayor = numTramo;
- tramoMayor = longTramo;
- }
- if(longTramo < tramoMenor || tramoMenor == 0){
- numTramoMenor = numTramo;
- tramoMenor = longTramo;
- }
- out.println();
- out.println("--Tramo #"+numTramo+"--");
- out.println("Longitud: "+longTramo);
- out.println("Relacion de inclinacion: "+relacInclinacion);
- out.println("Material: "+material);
- out.println("Clasificacion: "+clasificacion);
- out.println("Costo: "+costoTramo);
- }else{
- out.println("El tramo no se proceso");
- }
- out.println();
- out.println("Introduzca x2:");
- x2 = Integer.parseInt(in.readLine());
- out.println("Introduzca y2:");
- y2 = Integer.parseInt(in.readLine());
- }while(x2 != -1 && y2 != -1);
- out.println("--Informacion sobre la carretera--");
- out.println("Longitud total: "+longCarretera);
- out.println("Costo total: "+costoTotal);
- out.println("Tramo menor: #"+numTramoMenor+", con "+tramoMenor+"m");
- out.println("Tramo mayor: #"+numTramoMayor+", con "+tramoMayor+"m");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment