code sample icon Sample Code

In the generated Java class, after the first line:

                               
package oracle.model.freight;
                            

Delete all the generated code and replace with the following code:

                               
public enum CustomerCode{
  PLATINUM(20D),
  GOLD(10D), 
  SILVER(5D), 
  BRONZE(2D),
  OTHER(0D);
  
  Double factor;
  
  private CustomerCode(Double factor) {
    this.factor = factor;
  }
  
  public Double factor() {
    return this.factor;
  }
  
  public Double calculateDiscount(Double originalPrice) {
    return (originalPrice * factor)/ 100;
  }
}
                            

Instead of typing the sample code, you can copy the code in this window and then paste it into the source editor.

Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,