Skip to content

Instantly share code, notes, and snippets.

@Roberto24p
Last active August 9, 2019 19:59
Show Gist options
  • Save Roberto24p/e3bdca226a53078bca3b7b0e47d338ee to your computer and use it in GitHub Desktop.
Save Roberto24p/e3bdca226a53078bca3b7b0e47d338ee to your computer and use it in GitHub Desktop.
Aiuda
using Proyecto_Segundo_Parcial.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Proyecto_Segundo_Parcial.Control
{
class AdmBoletos
{
private static AdmBoletos admBoletos = null;
private AdmBoletos(){}
public static AdmBoletos getAdmBoletos()
{
if (admBoletos == null)
admBoletos = new AdmBoletos();
return admBoletos;
}
List<Boleto> datos = new List<Model.Boleto>();
public List<Boleto> getDatos() {
return datos;
}
public void setDatos(List<Boleto> datos) {
this.datos = datos;
}
public bool verificar(string tipodevuelo, string numerodeboleto, string precio)
{
bool bandera = false;
if (tipodevuelo.CompareTo("") != 0 && numerodeboleto.CompareTo("") != 0 && precio.CompareTo("") != 0)
{
bandera = true;
}
return bandera;
}
public string guardar(string tipodevuelo, string numerodeboleto, string Sprecio, string salida, string llegada, string fsalida, string fllegada)
{
Boleto boleto = new Boleto();
double precio = double.Parse(Sprecio);
boleto.setClasedevuelo(tipodevuelo);
boleto.setNumerodevuelo(numerodeboleto);
boleto.setPreciobo(precio);
//A partir de aqui empieza el error
boleto.getViaje().setorigen(salida);
boleto.getViaje().setllegada(llegada);
boleto.getViaje().setsalida(Convert.ToDateTime(fsalida));
boleto.getViaje().setllegada(Convert.ToDateTime(fllegada));
datos.Add(boleto);
return boleto.toString();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Proyecto_Segundo_Parcial.Model
{
class Boleto
{
private string clasedevuelo;
private string numerodevuelo;
private double preciobo;
private Viaje viaje;
//--------Constructor por defecto------------
public Boleto(){
}
//---------Constructor Parametrizado-----------
public Boleto(string clasedevuelo, string numerodevuelo, double preciobo,Viaje viaje)
{
this.clasedevuelo = clasedevuelo;
this.numerodevuelo = numerodevuelo;
this.preciobo = preciobo;
this.viaje = viaje;
}
//--------------Get y Set------------
public Viaje getViaje() {
return viaje;
}
public void setViaje(Viaje viaje) {
this.viaje = viaje;
}
public string getClasedevuelo() {
return clasedevuelo;
}
public void setClasedevuelo(string clasedevuelo) {
this.clasedevuelo = clasedevuelo;
}
public string getNumerodevuelo()
{
return numerodevuelo;
}
public void setNumerodevuelo(string numerodevuelo)
{
this.numerodevuelo = numerodevuelo;
}
public double getPreciobo()
{
return preciobo;
}
public void setPreciobo(double preciobo)
{
this.preciobo = preciobo;
}
//----------Metodos----------
/* public void IVA() {
double iva = 0, preciofinal;
iva = preciobo * 0.12;
preciofinal = iva + getPreciobo();
Console.WriteLine("IVA-->" + iva);
Console.WriteLine("Precio Final-->"+preciofinal);
}*/
public string toString()
{
return "\nClase de vuelo-->" + getClasedevuelo() + "\nNumero de boleto-->" + getNumerodevuelo() + "\nLugar de salida-->" + "\nPrecio del boleto-->" +getPreciobo() ;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Proyecto_Segundo_Parcial.Model
{
class Viaje
{
private DateTime fecha_salida;
private string hora_salida;
private DateTime fecha_llegada;
private string hora_llegada;
private string origen;
private string destino;
//constructor def
public Viaje() { }
//getters
public DateTime getsalida()
{
return fecha_salida;
}
public string gethorasalida()
{
return hora_salida;
}
public DateTime getllegada()
{
return fecha_llegada;
}
public string gethorallegada()
{
return hora_llegada;
}
public string getorigen()
{
return origen;
}
public string getdestino()
{
return destino;
}
//setters
public void setsalida(DateTime salida)
{
this.fecha_salida = salida;
}
public void setllegada(string horasalida)
{
this.hora_salida = horasalida;
}
public void setllegada(DateTime llegada)
{
this.fecha_llegada = llegada;
}
public void sethorallegada(string horallegada)
{
this.hora_llegada = horallegada;
}
public void setorigen(string origen)
{
this.origen = origen;
}
public void setdestino(string destino)
{
this.destino = destino;
}
public string toString()
{
return "fecha salida \n " + fecha_salida + " \n hora salida \n" + hora_salida + " \n fecha llegada \n" + fecha_llegada +
" \n hora llegada \n" + hora_llegada + " \n origen \n" + origen + " \n destino \n" + destino ;
}
}
}
@Roberto24p
Copy link
Author

Primera excepción del tipo 'System.NullReferenceException' en Proyecto Segundo Parcial.exe

@MrDave1999
Copy link

El error está en la clase Boleto. Faltó instanciar la clase Viaje (lo encuentras en la línea 14).

private Viaje viaje = new Viaje();

@Roberto24p
Copy link
Author

Muchas gracias MrDave :`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment