User talk:Spiderspider123

hellloo

// Write your complete code here. package bean;

public abstract class Item { private String itemName; private double price; /**	 * @param itemName * @param price */	public Item(String itemName, double price) { super; this.itemName = itemName; this.price = price; }	public String getItemName { return itemName; }	public void setItemName(String itemName) { this.itemName = itemName; }	public double getPrice { return price; }	public void setPrice(double price) { this.price = price; }	public abstract double calcActualPrice; }

package bean;

public class TV extends Item { private int screenSize; public TV(String itemName, double price,int screenSize) { super(itemName, price); this.screenSize=screenSize; }	public int getScreenSize { return screenSize; }

public void setScreenSize(int screenSize) { this.screenSize = screenSize; }

@Override public double calcActualPrice { if(screenSize==14) return (getPrice-(0.10*getPrice)); if(screenSize==21) return (getPrice-(0.12*getPrice)); if(screenSize>21) return (getPrice-(0.15*getPrice)); return 0; } }

package bean;

public class Refrigerator extends Item { private int capacity;

public Refrigerator(String itemName, double price,int capacity) { super(itemName, price); // TODO Auto-generated constructor stub this.capacity=capacity; }	public int getCapacity { return capacity; }

public void setCapacity(int capacity) { this.capacity = capacity; }

@Override public double calcActualPrice { if(capacity>=0 && capacity<=165) return (getPrice-(0.10*getPrice)); if(capacity>165 && capacity<=230) return (getPrice-(0.12*getPrice)); if(capacity>230) return (getPrice-(0.15*getPrice)); return 0; }

}

package controller; import view.*; public class Main { public static void main(String[] args){ menu m=new menu; int option=0; do { option=m.displayMenu; }while(option>=1 && option<=3); System.out.println("Program Ends"); } }

package model;

import java.util.Scanner;

import dao.Database;

import bean.*;

public class itemManager { public void getTVData{ Scanner s=new Scanner(System.in); System.out.println("Enter Screen Size : "); int scrn=s.nextInt; System.out.println("Enter Price : "); double d=s.nextDouble; TV t=new TV("TV",d,scrn); Database db=new Database; db.insertRecord(t); }	public void getRefrigeratorData{ Scanner s=new Scanner(System.in); System.out.println("Enter Capacity : "); int c=s.nextInt; System.out.println("Enter Price : "); double d=s.nextDouble; Refrigerator r=new Refrigerator("Refrigerator",d,c); Database db=new Database; db.insertRecord(r); }	public void readFromDB{ Database db=new Database; db.displayAllRecords; } }

package dao; import bean.*;

import java.sql.*;

public class Database { Connection con; Statement st; PreparedStatement ps; public Database { try{ Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:@172.0.0.100:1521:oracle"; con=DriverManager.getConnection(url,"scott","tiger"); }		catch(SQLException e){System.out.println(e); } catch(ClassNotFoundException ee){System.out.println("Driver Not Available : " + ee);} }	public void insertRecord(Item e) { try{ if(e instanceof TV || e instanceof Refrigerator ){ String query = "insert into ElectronicsItem_139 values(?,?,?)"; if(con != null) { ps = con.prepareStatement(query); ps.setString(1, e.getItemName); ps.setDouble(2, e.getPrice); ps.setDouble(3,e.calcActualPrice); int x = ps.executeUpdate; if(x == 0) System.out.println("insertion fails"); }		}	}		catch(SQLException ex){System.out.println("insertion fails "+ex); } }	public void displayAllRecords { try { if(con != null) { st=con.createStatement; ResultSet rs=st.executeQuery("select * from ElectronicsItem_139 where ItemName='TV'"); while(rs.next) System.out.println(rs.getString(1) + "\t" + rs.getDouble(2)+"\t"+rs.getDouble(3)); rs.close; }		}		catch(SQLException e){ } } }

package view; import model.itemManager;

import java.util.Scanner;

public class menu { public int displayMenu{ itemManager am=new itemManager; Scanner sc=new Scanner(System.in); System.out.println("1.Insert choice for TV"); System.out.println("2.Insert choice for Refrigerator"); System.out.println("3.Display all records from database"); System.out.println("Enter choice"); int ch=sc.nextInt; switch(ch){ case 1: am.getTVData; break; case 2: am.getRefrigeratorData; break; case 3: am.readFromDB; break; default:System.out.println("Invalid choice"); }		return ch; }

}