Compile-time question
Barry Burd
bburd at drew.edu
Sun Apr 7 11:56:16 PDT 2013
I'm able to compile this simple code ONLY if I comment out the call to p.display(). What am I doing wrong? Thanks.
import java.util.ArrayList;
class CheckAgeForDiscount {
ArrayList<Person> people = new ArrayList<Person>();
public static void main(String args[]) {
new CheckAgeForDiscount();
}
CheckAgeForDiscount() {
fillArray(people);
people.parallelStream()
.filter(p -> p.getAge() >= 12)
.filter(p -> p.getAge() < 65)
.forEach(p -> {
p.setPrice(9.25);
});
people.parallelStream()
.filter(p -> p.getAge() >= 12)
.filter(p -> p.getAge() < 65)
.filter(p -> p.hasCoupon())
.forEach(p -> {
p.setPrice(p.getPrice() - 2.00);
});
people.parallelStream()
.filter(p -> (p.getAge() < 12 || p.getAge() >= 65))
.forEach(p -> {
p.setPrice(5.25);
});
people.stream()
.forEach(p -> {
// p.display();
});
}
private void fillArray(ArrayList<Person> people) {
people.add(new Person("Barry", 62, true));
people.add(new Person("Harriet", 66, false));
people.add(new Person("Jennie", 6, true));
people.add(new Person("Sam", 8, false));
}
}
public class Person {
private String name;
private int age;
private boolean hasCoupon;
private double price;
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Person(String name, int age, boolean hasCoupon) {
super();
this.name = name;
this.age = age;
this.hasCoupon = hasCoupon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean hasCoupon() {
return hasCoupon;
}
public void hasCoupon(boolean hasCoupon) {
this.hasCoupon = hasCoupon;
}
private void display() {
System.out.print(getName());
System.out.print(": Please pay $");
System.out.print(price);
System.out.print(". ");
System.out.println("Enjoy the show!");
}
}
More information about the lambda-dev
mailing list