0

Why do I keep getting an "illegal start of expression error" for my method.

This is my code if you could please take a look. //////////////////////////// Separate File ///////////////////////////// public class BirthDate { // Attributes private Integer month; private Integer day; private Integer year; // Constructor public BirthDate(Integer m, Integer d, Integer y) { this.month = m; this.day = d; this.year = y; } // toString @Override public String toString() { return month + "-" + day + "-" + year + "-"; } // Equals method public boolean equals(BirthDate bd) { return this.month.equals(bd.month) && this.day.equals(bd.day) && this.year.equals(bd.year); } } ///////////////////////// Main method //////////////////// import java.util.*; public class BirthdayParadox { public static void main(String[] args) { ArrayList<BirthDate> bd = new ArrayList<>(); Scanner keyboard = new Scanner(System.in); Random randomNumbers = new Random(); int birthdates; int x = 0; System.out.println("How many birth dates would you like to check? "); birthdates = keyboard.nextInt(); createBirthDates(birthdates); // Method to create BirthDate objects public static BirthDate createBirthDates(int num) { do { int m; int d; int y; m = randomNumbers.nextInt(12) + 1; d = randomNumbers.nextInt(31) + 1; y = randomNumbers.nextInt(2020); bd.add(new BirthDate(m, d, y)); }while (x < num); } } } Any help is welcome. Thanks!

18th Jan 2020, 8:39 PM
Dario Alvarado
Dario Alvarado - avatar
2 odpowiedzi
+ 2
you are declaring createBirthDates() inside main() do it outside as separate method public static void main(String[] args) { } public static BirthDate createBirthDates(int num) { }
18th Jan 2020, 11:24 PM
zemiak
0
Thanks. I finally got it to work.
20th Jan 2020, 11:57 PM
Dario Alvarado
Dario Alvarado - avatar