Pages

Wednesday, 16 October 2013

Java program for fruit stall using inheritance and else if statement

import java.io.*;
class Fruits
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void disp()
{
System.out.println("1.mango");
System.out.println("2.orange");
System.out.println("3.pineapple");
System.out.println("4.grapes");
System.out.println("5.watermelon");
}
void val()
{
int man=50,ora=45,pine=25,grapes=34,watmel=56;
}
}
class simply extends Fruits
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
void ask()throws IOException
{
int man=50,ora=45,pine=25,grapes=34,watmel=56;
System.out.println("choose which fruit you want");
int fru=Integer.parseInt(br.readLine());
if(fru==1)
{
System.out.println("Enter how many kg you want");
int kg=Integer.parseInt(br.readLine());
int tot=kg*man;
System.out.println("the total kg is"+tot);
}
else if(fru==2)
{
int tot,kg;
System.out.println("Enter how many kg you want");
kg=Integer.parseInt(br.readLine());
tot=kg*ora;
System.out.println("The total kg is"+tot);
}
else if(fru==3)
{
int tot,kg;
System.out.println("Enter how many kg you want");
kg=Integer.parseInt(br.readLine());
tot=kg*pine;
System.out.println("The total kg is"+tot);
}
else if(fru==4)
{
int tot,kg;
System.out.println("Enter the how many kg you want");
kg=Integer.parseInt(br.readLine());
tot=kg*grapes;
System.out.println("the total value is"+tot);
}
else if(fru==5)
{
int tot,kg;
System.out.println("Enter the how many kg you want");
kg=Integer.parseInt(br.readLine());
tot=kg*watmel;
System.out.println("the total value is"+tot);
}
}
}
class FruitStall1
{
public static void main(String args[])throws IOException
{
simply s=new simply();
s.disp();
s.ask();
}
}

No comments:

Post a Comment