Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestProgramm {
- public static void main(String[] args) {
- Artikel a1;
- a1 = new Artikel();
- a1.name = "Heinz";
- a1.hersteller = "Ketchup";
- a1.kategorie = "Lebensmittel";
- a1.preis = 3;
- a1.nummer = 1;
- System.out.println("Name : " + a1.name);
- System.out.println("Hersteller : " + a1.hersteller);
- System.out.println("Kategorie : " + a1.kategorie);
- System.out.println("Preis: " + a1.preis);
- System.out.println("Nummer: " + a1.nummer);
- a1.ausgabe();
- System.out.println("\nNeues Objekt:\n");
- Artikel a2 = new Artikel();
- a2.name = "Merkur";
- a2.hersteller = "Haribo";
- a2.kategorie = "Lebensmittel";
- a2.preis = 2;
- a2.nummer = 2;
- a2.ausgabe();
- }
- public class Artikel {
- // Eigenschaften: Nummer, Name
- // Preis, Hersteller, Kategorie
- //Methoden: ausgabe(), Konstruktoren
- public double nummer;
- public double preis;
- public String name;
- public String hersteller;
- public String kategorie;
- public void ausgabe() {
- System.out.println("Nummer : " + this.nummer);
- System.out.println("Preis : " + this.preis);
- System.out.println("Name : " + this.name);
- System.out.println("Hersteller: " + this.hersteller);
- System.out.println("Kategorie: " + this.kategorie);
- }
- public Artikel(String name, String hersteller, String kategorie,
- double nummer, double preis) {
- // MemberVariable = LokaleParameterVariable
- this.name = name;
- this.hersteller = hersteller;
- this.kategorie = kategorie;
- this.nummer = nummer;
- this.preis = preis;
- }
- public Artikel() {}
- }
- }
Add Comment
Please, Sign In to add comment