Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekarstva;
- import java.util.Scanner;
- public class Lekarstvo {
- //тук пишеш за град - име, област, брой жители...
- private String name;
- private String strEffect;
- private int quantity;
- private double price;
- public Lekarstvo(String name,double price, int quantity, String strEffect) {
- this.name=name;
- this.strEffect=strEffect;
- this.quantity=quantity;
- this.price=price;
- }
- public Lekarstvo() {
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- //тук имам контрол на данните - ако ви иска контрол трябва да направите нещо подобно
- Scanner sc=new Scanner(System.in);
- while (name.length()<3) {
- System.out.println("Името е с твърде малка дължина.");
- name=sc.next();
- }
- this.name = name;
- }
- public String getStrEffect() {
- return strEffect;
- }
- public void setStrEffect(String strEffect) {
- this.strEffect = strEffect;
- }
- public int getQuantity() {
- return quantity;
- }
- public void setQuantity(int quantity) {
- Scanner sc=new Scanner(System.in);
- while (quantity<0) {
- System.out.println("Количеството трябва да е неотрицателно цяло число.");
- quantity=sc.nextInt();
- }
- this.quantity = quantity;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- //това също е контрол на данните
- Scanner sc=new Scanner(System.in);
- while (price<0) {
- System.out.println("Цената трябва да е неотрицателно число.");
- price=sc.nextInt();
- }
- this.price = price;
- }
- public void printLek() {
- System.out.println(name+" "+price+" Странични ефекти: "+strEffect+" Налични бройки: "+quantity);
- }
- }
RAW Paste Data