/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package packageA; import java.util.Scanner; /** * * @author MSI */ public class Product { private String code; protected String name; protected String size; public int price = 0; public Product(String code, String name, String size, int price) { this.code = code; this.name = name; this.size = size; this.price = price; } int input() { Scanner s = new Scanner(System.in); System.out.println("Input Code: "); code = s.nextLine(); s = new Scanner(System.in); System.out.println("Input Name: "); name = s.nextLine(); s = new Scanner(System.in); System.out.println("Input Size: "); size = s.nextLine(); do { try { System.out.println("Input Price: "); price = s.nextInt(); if (price < 0) throw new Exception("Wrong!! Price must > 0"); } catch(Exception x) { System.out.println("Wrong Number"); } } while (price < 0); return price; } @Override public String toString() { return "Product{" + "code=" + code + ", name=" + name + ", size=" + size + ", price=" + price + '}'; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } }