Hallo,
ich sollte für die Schule ein Programm schreiben, welches ein Auto erzeugen kann. Das ganze ist zur Verdeutlichung vom objektorientierten programmieren, allerdings kann das Programm vom JavaEditor nicht ausgeführt werden.
Wäre dankbar wenn jmd vll kurz über das Programm guckt
Auto.java:
AutoUIMenure.java:
Fehler: AutoUIMenue.java:19:5: non-static variable start cannot be referenced from a static context
start.menue(0);
Bin dankbar für Hilfe
ich sollte für die Schule ein Programm schreiben, welches ein Auto erzeugen kann. Das ganze ist zur Verdeutlichung vom objektorientierten programmieren, allerdings kann das Programm vom JavaEditor nicht ausgeführt werden.
Wäre dankbar wenn jmd vll kurz über das Programm guckt
Auto.java:
Java:
/**
*
* Beschreibung
*
* @version 1.0 vom 29.08.2013
* @author
*/
public class Auto {
// Anfang Attribute
// Attribut kennzeichen
private String kennzeichen;
public void setkennzeichen(String kennzeichen) {
this.kennzeichen = kennzeichen;
}
public String getKennzeichen() {
return (kennzeichen);
}
// Attribut marke
private String marke;
public void setmarke(String marke) {
this.marke = marke;
}
public String getmarke() {
return (marke);
}
// Attribut modell
private String modell;
public void setmodell(String modell) {
this.modell = modell;
}
public String getmodell() {
return (modell);
}
// Attribut kmStand
private double kmStand;
public void setkmStand(double kmStand) {
this.kmStand = kmStand;
}
public double getkmStand() {
return (kmStand);
}
// Attribut tankVolumen
private double tankVolumen;
public void settankVolumen(double tankVolumen) {
this.tankVolumen = tankVolumen;
}
public double gettankVolumen() {
return (tankVolumen);
}
// Attribut tankAktuell
private double tankAktuell;
public void settankAktuell(double tankAktuell) {
this.tankAktuell = tankAktuell;
}
public double gettankAktuell() {
return (tankAktuell);
}
// Attribut verbrauch
private double verbrauch;
public void setverbrauch(double verbrauch) {
this.verbrauch = verbrauch;
}
public double getverbrauch() {
return (verbrauch);
}
// Attribut identifikationsNR
private int idenktifikationsNR;
public void setidenktifikationsNR(int idenktifikationsNR) {
this.idenktifikationsNR = idenktifikationsNR;
}
public int getidenktifikationsNR() {
return (idenktifikationsNR);
}
// Ende Attribute
// Methode fahren
public void fahren(int km) {
double verbrauchAufStrecke = km/100.0 * this.verbrauch;
if (verbrauchAufStrecke <= this.tankAktuell) {
this.kmStand = this.kmStand + km;
this.tankAktuell = this.tankAktuell - verbrauchAufStrecke;
} else {
System.out.println("Nicht genügend Tank");
}
}
// Methode tanken
public void tanken() {
this.tankAktuell = this.tankVolumen;
}
// Konstruktor
public Auto(String kennzeichen, String marke, String modell, double kmStand, double tankVolumen, double tankAktuell, double verbrauch, int idenktifikationsnummer) {
this.kennzeichen = kennzeichen;
this.marke = marke;
this.modell = modell;
this.kmStand = kmStand;
this.tankVolumen = tankVolumen;
this.tankAktuell = tankAktuell;
this.verbrauch = verbrauch;
this.idenktifikationsNR = idenktifikationsnummer;
}
public Auto() {
}
// Anfang Methoden
public void toxString() {
System.out.println("Kennzeichen: "+kennzeichen);
System.out.println("Marke: "+marke);
System.out.println("Modell: "+modell);
System.out.println("KM Stand: "+kmStand);
System.out.println("Tank Volumen: "+tankVolumen);
System.out.println("Tank Aktuell: "+tankAktuell);
System.out.println("Verbrauch: "+verbrauch);
System.out.println("Identifikationsnummer: "+idenktifikationsNR);
}
// Ende Methoden
}
AutoUIMenure.java:
Java:
/**
*
* Beschreibung
*
* @version 1.0 vom 30.08.2013
* @author
*/
public class AutoUIMenue {
Auto einAuto = new Auto();
AutoUIMenue start = new AutoUIMenue();
// Anfang Attribute
private static int idenktifikationsnummer = 1;
// Ende Attribute
public static void main(String[] args) {
start.menue(0);
}
// Anfang Methoden
public void menue(int auswahl) {
System.out.println("Menue");
System.out.println("=====");
System.out.println();
System.out.println("1 - Attribute des Autos anzeigen");
System.out.println("2 - Auto fahren");
System.out.println("3 - Auto betanken");
System.out.println("3 - Programm beenden");
System.out.println();
switch (auswahl) {
case 1:
einAuto.toxString();
break;
case 2:
System.out.println("Wie weit moechten sie fahren?");
einAuto.fahren(Tastatur.leseZahl());
break;
case 3:
einAuto.tanken();
}
}
public void autoErstellen() {
System.out.println("Auto erstellen");
System.out.println("==============");
System.out.println();
System.out.println("Geben Sie das Kennzeichen ihres Auto ein:");
einAuto.setkennzeichen(Tastatur.leseText());
System.out.println("Geben sie bitte die Marke ihres Autos ein:");
einAuto.setmarke(Tastatur.leseText());
System.out.println("Geben sie bitte den Modellnamen ihres Autos ein:");
einAuto.setmodell(Tastatur.leseText());
System.out.println("Geben sie bitte den Kilometerstand ihres Auto ein:");
einAuto.setkmStand(Tastatur.leseKommazahl());
System.out.println("Geben sie bitte ");
einAuto.settankVolumen(Tastatur.leseKommazahl());
}
}
Fehler: AutoUIMenue.java:19:5: non-static variable start cannot be referenced from a static context
start.menue(0);
Bin dankbar für Hilfe