Question: Add insert , delete , update to this java code in mysql database : // create class Cake package cakebank; public class Cake { String

Add insert , delete , update to this java code in mysql database :

// create class Cake

package cakebank;

public class Cake {

String name; double rate; public Cake() { name=""; rate=0; } public Cake(String n,double r) { name=n; rate=r; } public String getName() { return name; } public double getRate() { return rate; } public void setName(String n) { name=n; } public void setRate(double r) { rate=r; } public double price() { return rate; } public String toString() { return "Name : "+name+" Rate : "+rate; } }

// Create Class OrderCake

package cakebank;

public class OrderCake extends Cake{

double weight; public OrderCake() { name=""; rate=0; weight=0; } public OrderCake(String n,double r,double w) { name=n; rate=r; weight=w; } public void setWeight(double w) { weight=w; } public double getWeight() { return weight; } public double price() { return weight*rate; } public String toString() { return "Name : "+name+" Price : "+weight*rate; } }

// Create Class ReadyMadeCake

package cakebank;

class ReadyMadeCake extends Cake{ int quantity; public ReadyMadeCake() { name=""; rate=0; quantity=0; } public ReadyMadeCake(String n,double r,int q) { name=n; rate=r; quantity=q; } public void setQuantity(int q) { quantity=q; } public double getQuantity() { return quantity; } public double price() { return quantity*rate; } public String toString() { return "Name : "+name+" Price : "+quantity*rate; } }

// Create Class PlaceOrder

// This class also contains the main class

package cakebank; import java.util.Scanner;

public class PlaceOrder {

public static void main(String[] args) { Cake[] arr=new Cake[20]; int i=0; Scanner sc=new Scanner(System.in); String opt; String n; double r; double q; int q2; double totalPrice=0; double readyMadePrice=0; double maxPrice=-1; int maxIndex=0; while(i<1){ System.out.println("Welcome To CAKEBANK"); System.out.println("BEST PLACE TO FIND CAKES"); System.out.println("Enter type of cake from below menu(1 or 2) for cake number "+(i+1)); System.out.println("1.Order on Choice"); System.out.println("2.Select from already avilable cakes!"); opt=sc.next(); if(opt.equals("1")) { System.out.println("Enter name of cake");

sc.nextLine(); n=sc.nextLine(); System.out.println("Enter rate of cake"); r=sc.nextDouble(); System.out.println("Enter Number of cake"); q=sc.nextDouble(); arr[i]=new OrderCake(n,r,q); totalPrice=totalPrice+arr[i].price(); if(maxPrice maxPrice=arr[i].price(); maxIndex=i; } i++;

} else if(opt.equals("2")) { System.out.println("Available Choices"); System.out.println("Dark Choclate"); System.out.println("Strawberry"); System.out.println("Blueberry"); System.out.println("White Choclate"); System.out.println("Enter name of cake"); sc.nextLine(); n=sc.nextLine(); System.out.println("Enter rate of cake"); r=sc.nextDouble(); System.out.println("Enter quantity of cake"); q2=sc.nextInt(); arr[i]=new ReadyMadeCake(n,r,q2); totalPrice=totalPrice+arr[i].price(); readyMadePrice=readyMadePrice+arr[i].price(); if(maxPrice maxPrice=arr[i].price(); maxIndex=i; } i++; } else { System.out.println("Invalid input!!"); } } System.out.println("Bill :: "); System.out.println(arr[maxIndex].toString()); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!