Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oop;
- public class oopfile {
- public static void main(String[] args) throws Exception {
- Kifli oopfile = new Kifli("Kifli", 120, "chocolate", 60);
- oopfile.printInfo();
- }
- }
- package oop;
- public class Kifli {
- String type;
- double volume;
- String filling;
- double quantity;
- public Kifli(String type, double volume, String filling, double quantity) {
- this.type = type;
- this.volume = volume;
- this.filling = filling;
- this.quantity = quantity;
- }
- void printInfo() {
- System.out.println("sugar product: " + this.type);
- System.out.println("volume: " + this.volume);
- System.out.println("filling: " + this.filling);
- System.out.printf("quantity: %.2f\n", this.quantity);
- }
- void put(double number) throws Exception {
- if ((number + this.quantity) > this.volume) {
- throw new Exception();
- } else {
- this.quantity += number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement