Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 24 of 24

Thread: I have problem a colections

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I have problem a colections

    Could someone guide me how to make printsortedCars
    line 32

    Code: https://pastebin.com/QqbHtMGj

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    Please post the code in question here on the forum. Be sure to wrap the code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    package myPackage.exam.colections;
     
    import java.util.*;
     
    public class Task2 {
        static Car BMW = new Car(true, 2005, 2, 1, 22000.0D);
        static Car AUDI = new Car(false, 2020, 1, 2, 604900.0D);
        static Car MERCEDES_BENZ = new Car(true, 2015, 3, 3, 75000.0D);
        static Car BMW_2 = new Car(true, 2003, 2, 4, 150000.0D);
        static Car FERRARI = new Car(true, 2020, 3, 5, 1230000.0D);
        static Car KIA = new Car(false, 2008, 2, 6, 13000.0D);
        static Car FORD = new Car(false, 2011, 2, 7, 8599.99D);
        static Car MCLAREN = new Car(true, 2018, 3, 8, 1700000.0D);
        static Car SKODA = new Car(false, 2001, 1, 9, 14000.0D);
        static Car DACIA = new Car(false, 1998, 1, 10, 6000.0D);
        private static final List<Car> carlist;
     
        public Task2() {
        }
     
     
        public static List<Car> getCarList() {
            Iterator var0 = carlist.iterator();
            if (var0.hasNext()) {
                Car c = (Car)var0.next();
                return (List)c;
            } else {
                return null;
            }
        }
     
        public static void printsortedCars() {
            //Print a list of cars to the console (you have to make the list yourself, preparing GOOD test data is part of the task)
            //the list should be sorted by attributes in the following order:
            //- exclusive cars are to be at the beginning of the list
            //- the newest cars, with the highest year of production, are to be displayed before older cars
            //- cars with higher equipment level are to be displayed before cars with lower equipment level
            //- more expensive cars should be displayed before cheaper cars
     
        }
     
        public static void printCarsToValueAndLevelOfEquipment(double maxValue, int levelOfEquipment) {
            // Business context: a customer goes to a used car dealership website and wants to see cars up to a certain "maxValue"
            // and having a specific equipment level e.g.: level 2 = car has air conditioning, and level 1 car has no air conditioning etc.
            //TASK: Filter and then list the cars from the cheapest to the most expensive from a list of cars
            //todo here the task
            for(Car a : carlist){
                System.out.println(a);
            }
            Collections.sort(carlist);
     
        }
     
        public static void addCardToList() {
            //todo
        }
     
        public static void removeCarFromList() {
            //todo
        }
     
        public static void printCarListAfterSomeModification() {
            //add 2-3 new cars to the list
            //remove 1-2 cars from the list
            // display the list
        }
     
        static {
            carlist = new LinkedList(Arrays.asList(BMW, AUDI, MERCEDES_BENZ, BMW_2, FERRARI, KIA, FORD, MCLAREN, SKODA, DACIA));
        }
     
        public static void main(String[] args) {
            printCarsToValueAndLevelOfEquipment(1,2);
            System.out.println(carlist);
        }
    }
     
     
    //Car.java
     
    package myPackage.exam.colections;
     
     
    public class Car implements Comparable<Car> {
        boolean isExclusive;
        int yearOfProduction;
        int levelOfEquipment;
        int id;
        double value;
     
        public Car(boolean isExclusive, int yearOfProduction, int levelOfEquipment, int id, double value) {
            this.isExclusive = isExclusive;
            this.yearOfProduction = yearOfProduction;
            this.levelOfEquipment = levelOfEquipment;
            this.id = id;
            this.value = value;
        }
     
        public boolean getExclusive() {
            return this.isExclusive;
        }
     
        public Integer getYear() {
            return this.yearOfProduction;
        }
     
        public Integer getlevel() {
            return this.levelOfEquipment;
        }
     
        public Integer getId() {
            return this.id;
        }
     
        public double getvalue() {
            return this.value;
        }
     
        public int compareTo(Car o) {
            return 0;
        }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    how to make printsortedCars
    What problems are you having with designing it?
    I see that The comments say what it is supposed to do.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Yes, it is but I don't know how to go about it

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    I don't know how to go about it
    Work through the problems one at a time.
    Post one of the problems you are having and describe what the code needs to do for that problem.

    If your problem is doing a sort, google about how to use the Comparator.
    For example: https://www.geeksforgeeks.org/compar...nterface-java/
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    When I want the console to list my cars, this pops up, how do I fix it?
    Console:
    myPackage.exam.colections.Car@3ac3fd8b
    myPackage.exam.colections.Car@5594a1b5
    myPackage.exam.colections.Car@6a5fc7f7
    myPackage.exam.colections.Car@3b6eb2ec
    myPackage.exam.colections.Car@1e643faf
    myPackage.exam.colections.Car@6e8dacdf
    myPackage.exam.colections.Car@7a79be86
    myPackage.exam.colections.Car@34ce8af7
    myPackage.exam.colections.Car@b684286
    myPackage.exam.colections.Car@880ec60

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    how do I fix it?
    Add a toString method to the Car class that returns the String you want to be shown on that print out.
    The Strings shown in that print out are what is returned by the default toString method for the Object class:
    <the full classname>@hexadecimalNumber
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Now I have a problem with displaying cars according to price and according to equipment level. I made scanners, I give variables, but in class printCardToValueAndLevelOfEquipment I don't know how in if to add cars value, Car.value doesn't work

       public static void printCarsToValueAndLevelOfEquipment(Scanner maxValue, Scanner levelOfEquipment) {
            // Business context: a customer goes to a used car dealership website and wants to see cars up to a certain "maxValue"
            // and having a specific equipment level e.g.: level 2 = car has air conditioning, and level 1 car has no air conditioning etc.
            //TASK: Filter and then list the cars from the cheapest to the most expensive from a list of cars
            //todo here the task
            for(Car a : carlist){
                if()
                System.out.println(a);
            }
            Collections.sort(carlist);
     
        public static void main(String[] args) {
            System.out.println("Enter maxValue: ");
            Scanner maxValue = new Scanner(System.in);
     
            double m = maxValue.nextDouble();
     
            System.out.println("Enter levelOfEquipment");
            Scanner levelOfEquipment = new Scanner(System.in);
     
            int l = levelOfEquipment.nextInt();
     
            System.out.println();
            printCarsToValueAndLevelOfEquipment(maxValue,levelOfEquipment);
     
        }
    }

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    Car.value doesn't work
    What does "doesn't work" mean?
    Is there an error message? Please copy the full text and paste it here.
    Executing the statement does not give the desired result. Print out any evidence that shows what the result is.

    What is the purpose of the two Scanner objects that are passed to the method?

    What is the purpose of the for loop?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    The purpose of the scanner is to enter the MaxValue of the cars and then in the console pop up cars up to a given amount, if I enter the amount of 2000, only cars up to 2k will be displayed, the same with levelofequipment

    --- Update ---

    package myPackage.exam.colections;
     
    import java.util.*;
     
    public class Task2 {
        static Car BMW = new Car(true, 2005, 2, 1, 22000.0D);
        static Car AUDI = new Car(false, 2020, 1, 2, 604900.0D);
        static Car MERCEDES_BENZ = new Car(true, 2015, 3, 3, 75000.0D);
        static Car BMW_2 = new Car(true, 2003, 2, 4, 150000.0D);
        static Car FERRARI = new Car(true, 2020, 3, 5, 1230000.0D);
        static Car KIA = new Car(false, 2008, 2, 6, 13000.0D);
        static Car FORD = new Car(false, 2011, 2, 7, 8599.99D);
        static Car MCLAREN = new Car(true, 2018, 3, 8, 1700000.0D);
        static Car SKODA = new Car(false, 2001, 1, 9, 14000.0D);
        static Car DACIA = new Car(false, 1998, 1, 10, 6000.0D);
        private static final List<Car> carlist;
     
        public Task2() {
        }
     
     
        public String getCarList() {
            return toString();
        }
     
        public static void printsortedCars() {
            //Wypisz na konsolę listę aut (listę należy zrobić samodzielnie, przygotowanie DOBRYCH danych testowych jest cześcią zadania)
            //lista ma być posotrowana po atrybutach w następującej kolejności:
            //- auta ekskluzywne mają znajdować się na początku listy
            //- auta najnowsze, o najwyższym roku produkcji, mają być wyświetlane przed autami starszymi
            //- auta o wyższym poziomie wyposażenia mają być przed autami o niższym poziomie wyposażenia
            //- auta droższe mają być wyświetlane przed tańszymi
        }
     
        public static void printCarsToValueAndLevelOfEquipment(Scanner maxValue, Scanner levelOfEquipment) {
            //Kontekst biznesowy: klient wchodzi na stronę salonu samochodów używanych i chce zobaczyć auta do pewnej kwoty "maxValue"
            // oraz mające konkretny poziom wyposażenia np: poziom 2 = auto ma klimatyzację, a poziom 1 auto klimatyzacji nie ma itp
            //ZADANIE: wyfiltruj a następnie wypisz auta od najtańszego do najdroższego z listy aut
            //todo tutaj wykonaj zadanie
            for(Car a : carlist){
                if()
                System.out.println(a);
            }
            Collections.sort(carlist);
     
        }
     
        public static void addCardToList() {
            //todo
        }
     
        public static void removeCarFromList() {
            //todo
        }
     
        public static void printCarListAfterSomeModification() {
            //dodaj 2-3 nowe auta do listy
            //usuń z listy 1-2 auta
            // wyświetl listę
        }
     
        static {
            carlist = new LinkedList(Arrays.asList(BMW, AUDI, MERCEDES_BENZ, BMW_2, FERRARI, KIA, FORD, MCLAREN, SKODA, DACIA));
        }
     
        public static void main(String[] args) {
            System.out.println("Enter maxValue: ");
            Scanner maxValue = new Scanner(System.in);
     
            double m = maxValue.nextDouble();
     
            System.out.println("Enter levelOfEquipment");
            Scanner levelOfEquipment = new Scanner(System.in);
     
            int l = levelOfEquipment.nextInt();
     
            System.out.println();
            printCarsToValueAndLevelOfEquipment(maxValue,levelOfEquipment);
     
        }
    }
     
     
     
    package myPackage.exam.colections;
     
     
    public class Car implements Comparable<Car> {
        boolean isExclusive;
        int yearOfProduction;
        int levelOfEquipment;
        int id;
        double value;
     
        public Car(boolean isExclusive, int yearOfProduction, int levelOfEquipment, int id, double value) {
            this.isExclusive = isExclusive;
            this.yearOfProduction = yearOfProduction;
            this.levelOfEquipment = levelOfEquipment;
            this.id = id;
            this.value = value;
        }
     
        public boolean getExclusive() {
            return this.isExclusive;
        }
     
        public Integer getYear() {
            return this.yearOfProduction;
        }
     
        public Integer getlevel() {
            return this.levelOfEquipment;
        }
     
        public Integer getId() {
            return this.id;
        }
     
        public double getvalue() {
            return this.value;
        }
     
        public int compareTo(Car o) {
            return 0;
        }
     
       // public String toString() {
        //return isExclusive + "" + yearOfProduction + "" + levelOfEquipment + "" + id + "" + value;
      //  }
     
        public String toString() {
            return this.isExclusive + " " + this.yearOfProduction + " " + this.levelOfEquipment + " " + this.id + " " + this.value;
        }
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    purpose of the scanner is to enter the MaxValue
    The values to test for should be acquired before the call to the method and then passed as a parameter to the method.
    The method should not be asking the questions and getting the responses.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    The purpose of the loop is to output the data information about the cars of the list.

    Unless I'm misunderstanding it and doing it wrong as you would. Because I don't understand your answer

    --- Update ---

    I wanted to make in if that if maxValue(e.g. we typed 10000 into the consola) > value (from the list) then the consola prints cars that cost up to 10000

    --- Update ---

    Do you understand? I enter 1000 in the console and it lists all cars that cost up to 1000, I enter equipment level 2 and it lists cars that have equipment level 2

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    I enter 1000 in the console
    You can use the Scanner class to read that number from the console outside of the printCarsToValueAndLevelOfEquipment method.
    Then pass that number to the method as an argument. See your post#3

    Note: It would be a better design to have separate print methods for the two items to search for:
    printCarsToValue(int value) and printCarsLevelOfEquipment(int level)

    On re-reading the method's comments I see that the method should select Cars that meet both criteria.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Quote Originally Posted by Norm View Post
    You can use the Scanner class to read that number from the console outside of the printCarsToValueAndLevelOfEquipment method.
    Then pass that number to the method as an argument.
    But I have it made

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    But I have it made
    What does that mean? If the code is designed and written incorrectly, it needs to be changed.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Then show me what you would change if you did

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    Look at post#9. It reads the values from the user in the main method into m and l.
    It should pass those values to the method as was done in post#3 instead of the 1,2 that was passed.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    I keep trying but I don't know how to add value from cars list to if.

    Because I don't know if you understand what he's trying to do.

    Scanner I created in order to create a variable, which then in a loop will check the value of vehicles and if I enter the value of 20000 will write me only vehicles to this amount

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    how to add value from cars list to if.
    The Car class needs to have get methods that return the value you want to test.
    In the foreach loop, the variable: a has the reference to the Car object.
    Note: a is a poor name for a variable that refers to a Car object. Better would be: aCar
    In the foreach loop, use the aCar variable to get the desired value from the Car object:
       ... aCar.getDesiredValue() ...

    The Scanner class usage should be like the code in post#9 - get the values to be passed to the method and then pass those values like was done on post#3.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Now in the loop it gives an error and intelijj wants to change getDesiredvalue from double to boolean

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    it gives an error
    Please copy the full text of the error message and paste it here.
    Also post the code where the error happens.

    Note: the name: getDesiredValue was only meant as an example. You need to change it to reflect what value that you want it to return from the Car class. For example: getTankSize or getCost or getWeight
    Look at the Car class's declaration, it has a get method for each value you might be interested in.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Dec 2021
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I have problem a colections

    Yes I know that getDesiredValue is as example

    package myPackage.exam.colections;
     
    import java.util.*;
     
    public class Task2 {
        static Car BMW = new Car(true, 2005, 2, 1, 22000.0D);
        static Car AUDI = new Car(false, 2020, 1, 2, 604900.0D);
        static Car MERCEDES_BENZ = new Car(true, 2015, 3, 3, 75000.0D);
        static Car BMW_2 = new Car(true, 2003, 2, 4, 150000.0D);
        static Car FERRARI = new Car(true, 2020, 3, 5, 1230000.0D);
        static Car KIA = new Car(false, 2008, 2, 6, 13000.0D);
        static Car FORD = new Car(false, 2011, 2, 7, 8599.99D);
        static Car MCLAREN = new Car(true, 2018, 3, 8, 1700000.0D);
        static Car SKODA = new Car(false, 2001, 1, 9, 14000.0D);
        static Car DACIA = new Car(false, 1998, 1, 10, 6000.0D);
        private static final List<Car> carlist;
     
        public String getCarList() {
            return toString();
        }
     
        public static void printsortedCars() {
            //Wypisz na konsolę listę aut (listę należy zrobić samodzielnie, przygotowanie DOBRYCH danych testowych jest cześcią zadania)
            //lista ma być posotrowana po atrybutach w następującej kolejności:
            //- auta ekskluzywne mają znajdować się na początku listy
            //- auta najnowsze, o najwyższym roku produkcji, mają być wyświetlane przed autami starszymi
            //- auta o wyższym poziomie wyposażenia mają być przed autami o niższym poziomie wyposażenia
            //- auta droższe mają być wyświetlane przed tańszymi
        }
     
        public static void printCarsToValueAndLevelOfEquipment(Scanner maxValue) {
            //Kontekst biznesowy: klient wchodzi na stronę salonu samochodów używanych i chce zobaczyć auta do pewnej kwoty "maxValue"
            // oraz mające konkretny poziom wyposażenia np: poziom 2 = auto ma klimatyzację, a poziom 1 auto klimatyzacji nie ma itp
            //ZADANIE: wyfiltruj a następnie wypisz auta od najtańszego do najdroższego z listy aut
            //todo tutaj wykonaj zadanie
            for(Car aCar : carlist){
                if(aCar.getValue())
                System.out.println(aCar);
            }
            Collections.sort(carlist);
     
        }
     
        public static void addCardToList() {
        }
     
        public static void removeCarFromList() {
            //todo
        }
     
        public static void printCarListAfterSomeModification() {
            //dodaj 2-3 nowe auta do listy
            //usuń z listy 1-2 auta
            // wyświetl listę
        }
     
        static {
            carlist = new LinkedList(Arrays.asList(BMW, AUDI, MERCEDES_BENZ, BMW_2, FERRARI, KIA, FORD, MCLAREN, SKODA, DACIA));
        }
     
        public static void main(String[] args) {
            System.out.println("Enter maxValue: ");
            Scanner maxValue = new Scanner(System.in);
     
            double m = maxValue.nextDouble();
     
            System.out.println();
            System.out.println("isExclusive " + "" + "yearofProduction " + "" + "levelofEquipment " + "      " + "id" + "        " + "value ");
            printCarsToValueAndLevelOfEquipment(maxValue);
     
            System.out.println("Enter levelOfEquipment: ");
            Scanner levelOfEquipment = new Scanner(System.in);
     
            int l = levelOfEquipment.nextInt();
     
            System.out.println();
            System.out.println("isExclusive " + "" + "yearofProduction " + "" + "levelofEquipment " + "      " + "id" + "        " + "value ");
            printCarsToValueAndLevelOfEquipment(levelOfEquipment);
     
        }
    }

    package myPackage.exam.colections;
     
     
    public class Car implements Comparable<Car> {
        boolean isExclusive;
        int yearOfProduction;
        int levelOfEquipment;
        int id;
        double value;
     
        public Car(boolean isExclusive, int yearOfProduction, int levelOfEquipment, int id, double value) {
            this.isExclusive = isExclusive;
            this.yearOfProduction = yearOfProduction;
            this.levelOfEquipment = levelOfEquipment;
            this.id = id;
            this.value = value;
        }
     
        public boolean getExclusive() {
            return this.isExclusive;
        }
     
        public Integer getYear() {
            return this.yearOfProduction;
        }
     
        public Integer getLevel() {
            return this.levelOfEquipment;
        }
     
        public Integer getId() {
            return this.id;
        }
     
        public double getValue() {
            return this.value;
        }
     
        public int compareTo(Car o) {
            return 0;
        }
     
        public String toString() {
            return this.isExclusive + "             " + this.yearOfProduction + "               " + this.levelOfEquipment + "               " + this.id + "         " + this.value;
        }
     
    }

    Error:
    java: incompatible types: double cannot be converted to boolean

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I have problem a colections

    The code is still passing the reference to the Scanner object instead of the value read in from the user into the variables: m and l

    Note: m and l are poor names for variables that hold important values. variable names should describe what they contain.
    For example: maxValue should hold the maximum value entered by the user.
    The name of the Scanner should describe what it is used for: readUserInput not maxValue


     if(aCar.getValue())   //java: incompatible types: double cannot be converted to boolean
    An if statement requires a boolean value. getValue returns a double
    Use a comparison operator to create a boolean expression:
     if(aCar.getValue() != 22.2)   // a boolean expression now
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Catch block problem. Please fix my problem.
    By damnitsme in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2014, 01:49 AM
  2. Problem with Project Euler problem 18
    By sara_magdy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2013, 12:46 PM
  3. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  4. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM
  5. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 04:30 AM