Está en la página 1de 3

UNIVERSIDAD DE LAS FUERZAS ARMADAS ESPE

CARRERA DE REDES Y TELECOMUNICACIONES

APLICACIONES MÓVILES
Integrantes: Michelle Troncoso, Jorge Luis Cujano NRC: 4295
Docente: Ing. Doris Chicaiza.

PROYECTO EXAMEN SEGUNDO PARCIAL


Captura de la interfaz.

CÓDIGO
public class MainActivity extends AppCompatActivity {
//declaración de variables
Button btncalcular;
EditText txtnum1, txtnum2, txtnum3,txtnum4, txtHost, txtClase,
txtMascara,txtHostResultado;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//mapeo de objetos
txtnum1=findViewById(R.id.et_num1);
txtnum2=findViewById(R.id.et_num2);
txtnum3=findViewById(R.id.et_num3);
txtnum4=findViewById(R.id.et_num4);
txtHost=findViewById(R.id.et_host);
btncalcular=findViewById(R.id.bt_calcular);
txtClase=findViewById(R.id.et_clase);
txtHostResultado=findViewById(R.id.et_host_res);
txtMascara=findViewById(R.id.et_mascara);
}
//crear metodo calcular mascara.
public void calcular(View view){
String rangoIP= txtnum1.getText().toString();
UNIVERSIDAD DE LAS FUERZAS ARMADAS ESPE
CARRERA DE REDES Y TELECOMUNICACIONES

Double RangoIp= Double.parseDouble(rangoIP);


//condiciones
if(RangoIp >= 0 && 128> RangoIp){
txtClase.setText("A");
txtMascara.setText("255.0.0.0");
}else if(RangoIp >= 128 && 192 > RangoIp){
txtClase.setText("B");
txtMascara.setText("255.255.0.0");
}else if(RangoIp >= 192 && 224 > RangoIp){
txtClase.setText("C");
txtMascara.setText("255.255.255.0");
}else if(RangoIp >= 224){
Toast.makeText(this, "Numero rango fuera de IP",
Toast.LENGTH_SHORT).show();
txtnum1.setText("");
txtnum2.setText("");
txtnum3.setText("");
txtnum4.setText("");
txtClase.setText("");
txtMascara.setText("");
}
}
public void NumSubred(View view){
double NumSubredTotal= 0;
double cantSubred= 0;
double numSubred= 0;
String hostIngresada= txtHost.getText().toString();
int subredIngresada= Integer.getInteger(hostIngresada);
for(int i=1;i<9;i++){
NumSubredTotal=(Math.pow(2,i)-2);
if(subredIngresada <= NumSubredTotal){
cantSubred= Math.pow(2,8-i);
numSubred= Math.pow(2,i);
String resultado= String.valueOf(cantSubred);
txtHostResultado.setText(resultado);
}
}
}
}

PROGRAMA EMULADO
UNIVERSIDAD DE LAS FUERZAS ARMADAS ESPE
CARRERA DE REDES Y TELECOMUNICACIONES

También podría gustarte