tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
452
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    PPhilipp PPhilipp ist offline Mitglied
    Registriert seit
    Nov 2003
    Ort
    Düsseldorf
    Beiträge
    18
    public class Shopping {

    /** Konstruktor von Shopping **//

    public Shopping () {

    }

    public void goShopping (int day, int hour, int minute) {}

    }


    Diese Klasse sol so erweitert werden, dass die Methode goShopping an Sonntagen (day == 7) und zwischen 20 und 8 Uhr mit einer neu programmierten Exception ShopsClosedException abgebrochen wird.
    Zusätzlich soll eine main-Methode eingefügt werden, die folgenden Code ausführt:

    Shopping food = new Shopping();
    food.goShopping (6, 15, 45);
    food.goShopping (4, 13, 11);
    food.goShopping (7, 9, 15);
     

  2. #2
    Registriert seit
    Nov 2001
    Ort
    Gießen
    Beiträge
    4.091
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    public class Shopping {
        public Shopping() {
     
        }
     
        public void goShopping(int day, int hour, int minute) 
        throws ShopsClosedException {
            if((day == 7) || (hour < 8) || (hour > 20)) {
                throw new ShopsClosedException();
            }
            // Laden ist noch offen
        }
     
        public static void main(String[] args) {
            try {
                Shopping food = new Shopping();
                food.goShopping (6, 15, 45);
                food.goShopping (4, 13, 11);
                food.goShopping (7, 9, 15);
            }
            catch(ShopsClosedException e) {
                // ...
            }
        }
    }
     
    "You could say that I was too lazy to calculate and so I invented the computer." -- Konrad Zuse

Ähnliche Themen

  1. Exceptions
    Von schiese im Forum Java Grundlagen
    Antworten: 5
    Letzter Beitrag: 24.08.10, 17:50
  2. Exceptions
    Von TheTank im Forum VisualStudio & MFC
    Antworten: 1
    Letzter Beitrag: 28.07.10, 07:43
  3. Exceptions
    Von lernen.2007 im Forum Java
    Antworten: 1
    Letzter Beitrag: 14.06.06, 13:17
  4. Exceptions
    Von lernen.2007 im Forum Java
    Antworten: 9
    Letzter Beitrag: 17.12.05, 18:14
  5. Exceptions wie in Java
    Von MD1978 im Forum .NET Archiv
    Antworten: 12
    Letzter Beitrag: 24.01.05, 17:27