Advertisement
BorislavaYordanova

Suit

May 1st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package ClothingItemShop;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7.  
  8. public class Suit extends ClothingItemShop {
  9.     private static float box_price;
  10.  
  11.     public Suit(float price_param, float weight_param, String color_param, String colorPattern_param, String size_param,
  12.             String fabric_param) {
  13.         super(price_param, weight_param, color_param, colorPattern_param, size_param, fabric_param);
  14.  
  15.     }
  16.  
  17.     static {
  18.         try {
  19.             Connection connection = null;
  20.             Statement statement = null;
  21.  
  22.             Class.forName("com.mysql.jdbc.Driver");
  23.             connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/clothingitem", "root", "123456");
  24.  
  25.             statement = connection.createStatement();
  26.             ResultSet result = statement
  27.                     .executeQuery("SELECT container_price FROM containers WHERE item_type = 'Suite'");
  28.  
  29.             while (result.next()) {
  30.                 box_price = result.getFloat("container_price");
  31.                 System.out.println("The box price for the Suite is: " + box_price);
  32.             }
  33.             result.close();
  34.             statement.close();
  35.             connection.close();
  36.         } catch (Exception e) {
  37.             System.out.print(e);
  38.         }
  39.     }
  40.  
  41.     public float getContainerPrice() {
  42.         return box_price;
  43.     }
  44.  
  45.     public float getWeight() {
  46.         return weight;
  47.     }
  48.  
  49.     public float getPrice() {
  50.         if (size.equals("L") || size.equals("XXL") || size.equals("XL")) {
  51.             return super.getItemPrice() * (float) 1.2;
  52.         } else {
  53.             return super.getItemPrice();
  54.         }
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement