Node Tem
Example heading with h2 size
Example heading with h3 size
Following is sample java code.
public static void main(String[] args) {
int op;
Scanner sc = new Scanner(System.in);
do {
char ans = 'n';
char anst = 'n';
LS ls;
Semanas Semana;
Node ptr;
int semNum;
int tiempo;
int dia;
int by;
String answer = JOptionPane.showInputDialog(
" MAIN MENU\n"
+ "1.Agregar Semana\n"
+ "2.Eliminar Semana\n"
+ // Que hace?
"3.Order\n"
+ "4.Exit\n");
op = Integer.parseInt(answer);
switch (op) {
case 1:
String semNum1 = JOptionPane.showInputDialog("Ingrese numero de semana");
semNum = Integer.parseInt(semNum1);
String Tiempo1 = JOptionPane.showInputDialog("Ingrese posicion del tiempo");
tiempo = Integer.parseInt(Tiempo1);
String dia1 = JOptionPane.showInputDialog("Ingrese posicion del dia");
dia = Integer.parseInt(dia1);
String by1 = JOptionPane.showInputDialog("Ingrese el byte");
by = Integer.parseInt(by1);
Semana = new Semanas(semNum, dia, tiempo, by);
Semana.asignarDatos();
ls = new LS(Semana);
ptr = ls.getHead();
view(ls.getHead());
System.out.println("¿Quiere agregar otra temperatura?");
anst = sc.next().charAt(0);
while(anst == 's'){
Semana = ptr.getSemana();
String TiempoS = JOptionPane.showInputDialog("Ingrese posicion del tiempo");
tiempo = Integer.parseInt(TiempoS);
String diaS = JOptionPane.showInputDialog("Ingrese posicion del dia");
dia = Integer.parseInt(diaS);
String byS = JOptionPane.showInputDialog("Ingrese el byte");
by = Integer.parseInt(byS);
Semana.Reasignar(dia, tiempo, by);
Semana.imprimirDatos();
ptr.setSemana( Semana);
view(ls.getHead());
System.out.println("¿Quiere agregar otra temperatura?");
anst = sc.next().charAt(0);
}
System.out.println("¿Quiere agregar otra semana?");
ans = sc.next().charAt(0);
if (ans == 's') {
String semNum2 = JOptionPane.showInputDialog("Ingrese numero de semana");
semNum = Integer.parseInt(semNum2);
String Tiempo2 = JOptionPane.showInputDialog("Ingrese posicion del tiempo");
tiempo = Integer.parseInt(Tiempo2);
String dia2 = JOptionPane.showInputDialog("Ingrese posicion del dia");
dia = Integer.parseInt(dia2);
String by2 = JOptionPane.showInputDialog("Ingrese el byte");
by = Integer.parseInt(by2);
Semana.imprimirDatos();
ls.addEnd(Semana);
view(ls.getHead());
ptr = find(ls.getHead(), 2);
}
break;
case 2:
break;
case 3:
break;
case 4:
System.exit(0);
break;
default:
break;
}
} while (op != 4);
}
public static void view(Node ptr) {
Semanas Semana;
while (ptr != null) {
Semana = ptr.getSemana();
System.out.println("El numero de semana es:"+ Semana.getSemNum());
JOptionPane.showMessageDialog(null, Semana.asignarDatos());
ptr = ptr.next;
}
System.out.println();
}
public static Node find(Node head, int semNum) {
Node ptr = head;
while (ptr != null && ptr.getSemana().getSemNum() != semNum) {
ptr = ptr.getNext();
}
return ptr;
}
import java.util.Arrays;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Semanas {
private int semNum;
private int Tem[][] = new int[5][5];
private int dia;
private int tiempo;
private int by;
private char ans;
public Semanas(int SemNum,int dia, int tiempo, int by) {
this.dia = dia;
this.tiempo = tiempo;
this.by = by;
this.Tem[this.dia][this.tiempo] = (this.by * 300) / 1023;
}
public int getSemNum() {
return semNum;
}
public void setSemNum(int semNum) {
this.semNum = semNum;
}
public int[][] getTem() {
return Tem;
}
public void setTem(int[][] Tem) {
this.Tem = Tem;
}
public int getDia() {
return dia;
}
public void setDia(int dia) {
this.dia = dia;
}
public int getTiempo() {
return tiempo;
}
public void setTiempo(int tiempo) {
this.tiempo = tiempo;
}
public int getBy() {
return by;
}
public void setBy(int by) {
this.by = by;
}
public int Menu() {
int op;
String answer = JOptionPane.showInputDialog(
" MAIN MENU\n"
+ "1.Agregar Temperatura\n"
+ // Que hace?
"2.Eliminar temperatura\n"
+ "3.Imprimir Matriz\n"
+ "4.Exit\n");
op = Integer.parseInt(answer);
return op;
}
public void Reasignar(int dia, int tiempo, int by){
this.dia = dia;
this.tiempo = tiempo;
this.by = by;
this.Tem[this.dia][this.tiempo] = (this.by * 300) / 1023;
}
public void AgregarDato() {
int tiempo;
int dia;
int by;
String Tiempo1 = JOptionPane.showInputDialog("Ingrese posicion del tiempo");
tiempo = Integer.parseInt(Tiempo1);
String dia1 = JOptionPane.showInputDialog("Ingrese posicion del dia");
dia = Integer.parseInt(dia1);
String by1 = JOptionPane.showInputDialog("Ingrese el byte");
by = Integer.parseInt(by1);
}
public String imprimirDatos() {
Scanner sc = new Scanner(System.in);
//Tem[this.tiempo][this.dia] = (this.by * 300) / 1023;
//System.out.println(Tem[tiempo][dia] + " C ");
int diaN[] = new int[5];
for (int i = 0; i < diaN.length; i++) {
diaN[i] = (i + 1);
}
for (int i = 0; i < diaN.length; i++) {
if (i == 0) {
System.out.print(" Dia" + (diaN[i]) + " ");
} else {
System.out.print("Dia" + (diaN[i]) + " ");
}
}
System.out.println("\n");
for (int i = 0; i < this.Tem.length; i++) {
for (int j = 0; j < this.Tem.length; j++) {
if (j == 0) {
System.out.print("Tiempo " + (j + 1) + " " + Tem[i][j] + " C ");
} else {
System.out.print(Tem[i][j] + " C ");
}
}
System.out.print("\n");
}
// int aux;
// for (int i = 0; i < 5; i++) {
// for (int j = 0; j < 5; j++) {
// if (Tem[i][j] > Tem[i + 1][j + 1]) {
// aux = Tem[i][j];
// Tem[i][j] = Tem[i + 1][j + 1];
// Tem[i + 1][j + 1] = aux;
//
// }
//
// }
//
// }
String resultado = "";
for (int i = 0; i < this.Tem.length; i++) {
for (int j = 0; j < this.Tem.length; j++) {
resultado += this.Tem[i][j];
resultado += " ";
}
resultado += "\n";
}
return resultado;
}
public void EliminarDatos() {
do {
Scanner sc = new Scanner(System.in);
System.out.println("Ingrese posicion del tiempo");
tiempo = sc.nextInt();
System.out.println("Ingrese posicion del dia");
dia = sc.nextInt();
Tem[tiempo][dia] = 0;
System.out.println(Tem[tiempo][dia] + " C ");
int diaN[] = new int[5];
for (int i = 0; i < diaN.length; i++) {
diaN[i] = (i + 1);
}
for (int i = 0; i < diaN.length; i++) {
if (i == 0) {
System.out.print(" Dia" + (diaN[i]) + " ");
} else {
System.out.print("Dia" + (diaN[i]) + " ");
}
}
System.out.println("\n");
for (int i = 0; i < Tem.length; i++) {
for (int j = 0; j < Tem.length; j++) {
if (j == 0) {
System.out.print("Tiempo " + (i + 1) + " " + Tem[i][j] + " C ");
} else {
System.out.print(Tem[i][j] + " C ");
}
}
System.out.print("\n");
}
System.out.println("Quiere eliminar otra temperatuta");
ans = sc.next().charAt(0);
} while (ans == 's');
}
}
public class LS {
private Node head;
public LS(){
head = null;
}
public LS(Semanas Semana){
this.head = new Node(Semana);
head.setNext(null);
}
public void setHead(Node head){
this.head = head;
}
public Node getHead() {
return head;
}
// Functional methods
public boolean empthy() {
return head == null;
}
public void insBefore(Node ptr, Semanas Semana) {
Node aux;
if (head == null) {
head = new Node(Semana);
} else if (ptr != null) {
aux = new Node(ptr.getSemana());
ptr.setSemana(Semana);
aux.setNext(ptr.getNext());
ptr.setNext(aux);
}
}
public void addEnd(Semanas Semana){
Node aux = new Node(Semana);
if(head == null){
head = aux;
}else{
Node curr = head;
while(curr.next!= null){
curr = curr.next;
}
curr.next = aux;
}
}
// public void insLater(Node ptr, Semanas Semana) {
// Node aux;
// if (head == null) {
// head = new Node(Semana);
// } else if (ptr != null) {
// aux = new Node(Semana);
//// aux.setNext(ptr.getNext());
// ptr.setNext(aux);
// }
// }
public void remove(Node ptr) {
if (ptr != null && ptr.getNext() != null) {
Node aux = ptr.getNext();
ptr.setSemana(aux.getSemana());
ptr.setNext(aux.getNext());
aux.setNext(null);
aux = null;
}
}
}