Java program to calculate charges of trunk calls using polymorphism

itstudentjunction


Java program to calculate charges of trunk calls using polymorphism - java programs


//Java program to calculate charges of trunk calls using polymorphism



import java.io.*;
class call {
float dur;
String type;
float rate()
{if(type.equals("urgent"))
return 4.5f;
else if(type=="lightning")
return 3.5f;
else
return 3f;
} }


class bill extends call
{
float amount;
DataInputStream in=null;
bill()
{
try {in=new DataInputStream(System.in);
}catch(Exception e)
{ System.out.println(e); }
}void read()throws Exception
{
String s; System.out.println("enter call type(urgent,lightning,ordinary):");
type=in.readLine();
System.out.println("enter call duration:");
s=in.readLine();
dur=Float.valueOf(s).floatValue();
}void calculate() {
if(dur<=1.5)
amount=rate()*dur+1.5f;
else if(dur<=3)
amount=rate()*dur+2.5f;
else if(dur<=5)
amount=rate()*dur+4.5f;
else
amount=rate()*dur+5f;
}void print() { System.out.println("**********************");
System.out.println(" PHONE BILL "); System.out.println("**********************"); System.out.println(" Call type : "+type);
System.out.println(" Duration : "+dur);
System.out.println(" CHARGE
: "+amount); System.out.println("**********************");
} }

class trunc-call
{public static void main(String arg[])throws Exception
{bill b=new bill();
b.read();
b.calculate();
b.print();
}
}

 


Custom Search



java program to add two numbers check a number is armstrong or not program to check prime numbers below range number is prime or not find a string is palindrome or not java program to connect to mysql database java program to connect to oracle database count characters, words lines in a string java program to copy one file into another find factorial of a number find fibonacci series find palindrome of a number find roots of quadriatic equation java program to find simple interest implement stack list files in a directory multiply two matrices java program to print pascals triangle read a file read a file line by line java program to reverse a given number show arithmetic operations java program to show current current date and timejava program to show maximum of two numbers To sort list of strings Find Area of rectangle Arthemetic logic relational operations break and continue statements average of marks multiplication of matrices sum of digits objects of rectangle class show constructor overloadingprivate member of a super class show inheritance show polymorphismusing polymorphism.import package show the usefulness of Interfaces as a place to keep constant value of the program. show method overriding implementation of interfaceArrayindexoutofboundexceptiondivide by zero exception. number format exception using synchronisation show multithreading with priority Count threads generate two threads for counting even or odd numbers using thread synchronization in multithreading ( create String object Initialize with name Find length character ‘a’ is in your name or not & number of times ‘a’ appears in name & Print locations String handling first and last occurrenc occurrence of a character in string Exercise 4: convertstring from console to upper case and print on console. java program in Java, takes the name of a file reads name & display on console. Exercise 6:copy a file i Exercise 1: Write a Java Applet program which reads your name and address in different text fields and when a button named find is pressed the sum of the length of characters in name and address is displayed in another text field. Use appropriate colors, layout to make your applet look good. Exercise 2: Create an applet which displays a rectangle/string with specified colour & coordinate passed as parameter from the HTML file. Exercise 3: Create an applet which will display the calendar of a given date. Exercise 4: Write a program to store student’s detail using Card Layout text area with horizontal and vertical scrollbarsd find a word in the content of the text area or not Ignou Mca assignments Ignou bca assignments C ProgramsC Lab records Data structures Programs in c Data structures Programs in c++ Computer Graphics ProgramsComputer Graphics ProgramsComputer Graphics lab programs Unix commandsunix lab solutions> Linux commands Linux lab solutions HTML programming HTML lab programs C++ programs, C++ Lab programs Data structures AlgorithmsWeb technologies programmingWeb technologies Lab programs Java Programs Java lab programs UML Diagrams uml LabAssembly Language Programs