TestCakeProgram.java:30: error: cannot find symbe ob[i] = new orderCake(w,name,rateO); symbol: variable rateo location: class TestCakeProgram 1 error Jot compiled
NEED HELP WITH JAVA PROGRAM
PLEASE HELP THANK YOU .
-ERROR SEE IMAGE BELOW
Cake.java
public abstract class Cake{
protected String name;
protected double rate;
protected double calcPrice;
public Cake(String n, double r)
{
name = n;
rate = r;
}
public abstract double calcPrice();
public String toString()
{
return name + "\t" +rate;
}
}
class orderCake extends Cake
{
double weight;
public orderCake(double weight,String n, double r)
{
super(n,r);
this.weight= weight;
}
public double calcPrice()
{
return rate * weight;
}
}
class readymadeCake extends Cake
{
double quantity;
public readymadeCake(double quantity,String n, double r)
{
super(n,r);
this.quantity= quantity;
}
public double calcPrice()
{
return rate * quantity;
}
}
TestCakeProgram.java
import java.util.Scanner;
class TestCakeProgram
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int choice=0;
System.out.println("ENTER RATE FOR ORDERED CAKE: ");
double rate0=sc.nextDouble();
System.out.println("ENTER RATE FOR READYMADE CAKE: ");
double rateR=sc.nextDouble();
Cake ob[] = new Cake[2];
double w=0,q=0;
double totalO=0.0,totalP=0.0;
double quant=0;
double max=0;
String nameOf="";
String name="";
for(int i=0;i<2;i++)
{
System.out.println("ENTER ( 1 ) ORDER CAKE AND ( 2 ) READYMADE CAKE : ");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("ENTER NAME: ");
name=sc.next();
System.out.println("ENTER WEIGHT: ");
w=sc.nextDouble();
ob[i] = new orderCake(w,name,rateO);
totalO=totalO+ob[i].calcPrice();
if(max<ob[i].calcPrice())
{
max=ob[i].calcPrice;
nameOf=name;
}
}
else if(choice==2)
{
System.out.println("ENTER NAME: ");
name=sc.next();
System.out.println("ENTER QUANTITY: ");
q=sc.nextDouble();
quant =quant +q;
ob[i] = new readymadeCake(q,name,rateR);
totalP=totalP+ob[i].calcPrice();
if(max<ob[i].calcPrice())
{
max=ob[i].calcPrice();
nameOf=name;
}
}
}
System.out.println("TOTAL PRICE OF ALL CAKES: "+totalO+totalP);
System.out.println("TOTAL PRICE OF READYMADE CAKES: "+totalP+"AND QUANTITY IS: "+quant);
System.out.println("HIGHEST PRICE FOR THE CAKE IS: "+max+"CAKE NAME IS:"+nameOf);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images