Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package electronicsequipmentdemo;
- public class Product {
- private String productCode;
- private double pricePerUnit;
- public Product(String productCode, double pricePerUnit) throws InvalidProductCodeException{
- if(productCode.length()==7){
- char[] temp = (productCode.substring(0, 2)).toCharArray();
- for(char ch : temp){
- if(!Character.isLetter(ch)){
- throw new InvalidProductCodeException();
- }
- }
- if(productCode.charAt(2) != '/'){
- throw new InvalidProductCodeException();
- }
- temp = (productCode.substring(3, 7)).toCharArray();
- for(char ch : temp){
- if(!Character.isDigit(ch)){
- throw new InvalidProductCodeException();
- }
- }
- this.productCode = productCode;
- this.pricePerUnit = pricePerUnit;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement