Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- //import java.io.*;
- public class Solicitud{
- static class Lista<T> {
- static class NodoLista<T> {
- private NodoLista<T> anterior;
- private NodoLista<T> siguiente;
- private String cedula;
- private String texto;
- private double promedio;
- private String codigo;
- private int creditos;
- public NodoLista(double promedio,String cedula,String texto,int creditos, String codigo) {
- this.promedio=promedio;
- this.cedula = cedula;
- this.texto = texto;
- this.codigo=codigo;
- this.creditos=creditos;
- siguiente = anterior = null;
- }
- }
- NodoLista<T> frente;
- NodoLista<T> cola;
- int longitud=0;
- public Lista() {
- frente = cola = null;
- longitud = 0;
- }
- public void insertarFrente(double promedio,String cedula,String texto,int creditos, String codigo) {
- NodoLista<T> nodo = new NodoLista<>(promedio,cedula,texto, creditos,codigo);
- if (longitud == 0) {
- cola = nodo;
- } else {
- frente.anterior = nodo;
- nodo.siguiente = frente;
- }
- frente = nodo;
- longitud++;
- }
- //biene
- public String removerFrente(){
- String codigo= frente.codigo;
- frente = frente.siguiente;
- longitud--;
- if (longitud > 0) {
- frente.anterior = null;
- }
- return codigo;
- }
- public String removerCola() {
- String codigo=cola.codigo;
- cola = cola.anterior;
- longitud--;
- if (longitud > 0) {
- cola.siguiente = null;
- }
- return codigo;
- }
- public String remover(int posicion) { //remover el codigo y todo el nodo
- if (posicion == 0) {
- return removerFrente();
- }
- if (posicion == longitud-1) {
- return removerCola();
- }
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++) {
- ref = ref.siguiente;
- }
- String codigo = ref.codigo;
- ref.anterior.siguiente = ref.siguiente;
- ref.siguiente.anterior = ref.anterior;
- longitud--;
- return codigo;
- }
- public double valorEn(int posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.promedio;
- }
- public int creditos(int posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.creditos;
- }
- public String cedulaEn( Integer posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.cedula;
- }
- public String motivo( Integer posicion){ //valor en la posicion metodo
- NodoLista<T> ref = frente;
- for (int i = 0; i < posicion; i++, ref = ref.siguiente);
- return ref.texto;
- }
- }
- public static void main(String[] args) {
- //try{
- Lista<Object> lista = new Lista<>();
- Scanner teclado= new Scanner(System.in);
- //System.out.println("escriba solicitud o atender");
- while(teclado.hasNext()){
- String queja=teclado.next();
- if (queja.equals("solicitud")) {
- //System.out.println("digite su cedula y codigo de asignatura ");
- String cedula=teclado.next();
- String codigo=teclado.next();
- //System.out.println("que reclamo tiene? ");
- teclado.nextLine();
- String texto = teclado.nextLine();
- //System.out.println("digite su PAPA ");
- int creditos=Integer.parseInt(teclado.nextLine());
- double promedio=Double.parseDouble(teclado.nextLine());
- double Pappi=((promedio/creditos)*1000000)/1000000;
- lista.insertarFrente(Pappi, cedula, texto,creditos,codigo); //lo inserto en ua pila
- }
- else {
- //System.out.println(lista.longitud);
- if (lista.longitud>0){
- double mayor=0;
- for (int n=0;n<lista.longitud;n++){ //for para buscar el PAPPI mayor
- if(lista.valorEn(n)>= mayor){
- mayor=lista.valorEn(n);
- }
- }
- int credit=0;
- int posR=0;
- for (int n=0;n<lista.longitud;n++){ //bucle para encontrar la posicion que llego primero y tiene el mayor PAPPi
- if( lista.valorEn(n)== mayor && lista.creditos(n)>=credit ){
- credit=lista.creditos(n);
- posR=n; //posicion que busco
- }
- }
- System.out.println(lista.cedulaEn(posR)+","+lista.motivo(posR)+","+lista.remover(posR) ); //muestro los datos y lo remuevo
- }
- else {
- System.out.println("Todos tienen cupo");
- continue;
- }
- }
- }
- teclado.close();
- // }catch(Exception e){
- // System.err.println (e.getMessage ());
- // return;
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement