1. Liebe Forumsgemeinde,

    aufgrund der Bestimmungen, die sich aus der DSGVO ergeben, müssten umfangreiche Anpassungen am Forum vorgenommen werden, die sich für uns nicht wirtschaftlich abbilden lassen. Daher haben wir uns entschlossen, das Forum in seiner aktuellen Form zu archivieren und online bereit zu stellen, jedoch keine Neuanmeldungen oder neuen Kommentare mehr zuzulassen. So ist sichergestellt, dass das gesammelte Wissen nicht verloren geht, und wir die Seite dennoch DSGVO-konform zur Verfügung stellen können.
    Dies wird in den nächsten Tagen umgesetzt.

    Ich danke allen, die sich in den letzten Jahren für Hilfesuchende und auch für das Forum selbst engagiert haben. Ich bin weiterhin für euch erreichbar unter tti(bei)pcwelt.de.
    Dismiss Notice

Java CarDealer Hilfe!!!

Discussion in 'Programmieren' started by xxoljenkaxx, Oct 9, 2010.

Thread Status:
Not open for further replies.
  1. Hi,
    sitz grad an eine Aufgabe versuch schon seid stunden die richtig durchzublicken aber irgendwie gehts nicht, vllt könnt ihr mir da behilflich sein.

    Aufgabenstellung

    A car dealer wants to administer his total fleet of cars. He sells different brands of cars of various
    years of construction. When a customer comes in with a question like: “What cars do you have
    of a price between €10.000 and €15.000?” he wants to be able to present a complete list of
    possible cars with all the important details. To create such an application you are given the
    skeletons of two classes below. In the class Car you will find an attribute code, this is an
    internal code used within the administration of the shop, it has no relation with the number plate
    of the car.

    hab 2 Classen gemacht
    und soweit bin ich jetzt
    Code:
    public class Car{
        private String brand;
        private String type;
        private int yearOfConstruction;
        private int price;
        private String code;
        
        public Car(String brand, String type, int yearOfConstruction, int price, String code)
            {
               
            }
        
        public Car(String brand, String type, int yearOfConstruction) 
        {
            
            
        }
       
     //getters and setters
        public boolean equals(Car a)
        {
            //To do: only compare the important attributes
            for (Car c:cars )       
            {
                if (c.yearOfConstruction > preismin && c.getpreis < preismax) {
                 c.gibAlleRelevantenDatenAus();
                 return cars;
                }
            }
        }
        
        public String toString()
                {
                    //To do concatenate the attributes to a single string:
                    
                    return ("Das sind die ausgewählten namen" + Car);
        
                } 
                
          public String getPriceOfCar(int i){
            cars.get(i).getPrice();
            
        }
        
        public Car getMostExpensiveCar(){
            //To do:
        }
    }
    und die nächste classe ist :
    Code:
    import java.util.*;
    public class CarDealership
    {
        private ArrayList<Car> cars;
        
        public CarDealership()
        {
            cars = new ArrayList<Car>();
        }
        
        public void addCar(Car a )
        {
            cars.add(a);
        }
        
        public void printCars(){
            for(Car a:cars)
            {
              System.out.println(a); 
            }
        }
        
        public int numberOfCars()
        {
           return cars.size();
        }
        
         public int getTotalValue()
        {
            //To do: sum all the prices of the cars in the shop
            
        }
        
        public int getPriceOfCar(int i)
        {
          for(Car Car: cars)
          {
            return cars;       
          }
        }
        
        public void increaseAllPrices(double percent){
            //To do: increase all the prices with percent (note that 0<percent<100)
        }
        
        public Car getMostExpensiveCar(){
            //To do:
        }
        
        public int searchCarWithCode(String code){
            //To do: code is the internal code, used within the administration
        }
        
        public Car searchSpecificCar(Car car){
            //To do:
        }
        
        public ArrayList<Car> carsInRange(int min, int max){
            //To do: search all the cars with a price that lies between min and max and return these
            //cars as an ArrayList
        }
       
    }
    kp was ich da machen soll
     
  2. kingjon

    kingjon Ganzes Gigabyte

    Hätts ma inner Schule besser aufgepasst! :)

    Gruß kingjon
     
  3. hat ja nix mit schule zu tun hätten wir es besprochen könnt ichs ja warscheinlich
     
  4. daboom

    daboom Megabyte

    Wo denn besprochen, wenn nicht in der Schule?

    Was mich trotzdem interessieren würde, was genau hast Du zu den "Skeletons" hinzugefügt, als das, was Du da gepostet hast, rausgekommen ist, also wie sahen diese "Skeletons" ursprünglich aus?
     
  5. Hascheff

    Hascheff Moderator

    Schreib mal deutsch. Wenn er Englisch könnte, hätte er die Aufgabe modifiziert.
     
  6. daboom

    daboom Megabyte

    Was meinst Du mit "modifziert"?
     
  7. fred5261

    fred5261 ROM

    Die Aufgabe ist doch eigentlich kinderleicht zu lösen:

    Code:
    public List<Car> carsInRange(int min, int max) {
        List<Car> results = new ArrayList<Car>();
        for (Car car : this.cars) {
            if ((car.getPrice() >= min) && (car.getPrice() <= max)) {
                results.add(car);
            }
        }
        return results;
    }
    Dein Quelltext enthält übrigens etliche Fehler. Die Car-Klasse würde ich als reine Bean realisieren und mit standardkonformen Gettern und Settern versehen.

    Siehe:
    http://openbook.galileocomputing.de...07_004.htm#mjd355ce523d3c71ae959044da5656ce1a
    http://en.wikipedia.org/wiki/JavaBean

    Einfaches Beispiel für die Property price:

    Code:
    private int price;
    
    public int getPrice() {
        return this.price;
    }
    
    public void setPrice(int price) {
        this.price = price;
    }
    
    Absolut tabu sind Methoden wie "getMostExpensiveCar" oder "getPriceOfCar(int i)" in der Car-Bean, da diese auf andere Beans zugreifen und Applikationslogik enthalten, die nichts in der Bean zu suchen hat.Solche Methoden gehören in eine übergeordnete Klasse zur Verwaltung der Beans, z.B. eine Datenbank-Klasse, welche du durch die Klasse CarDealership ja schon prototypisch angefangen hast. Implementierungen von equals(..), compareTo(..), toString() etc sind hingegen OK.
     
    Last edited: Oct 10, 2010
Thread Status:
Not open for further replies.

Share This Page