






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
THIS IS USEFUL FOR GRADE 10 ICSE STUDENTS. PROGRAMS BASED ON CONSTRUCTORS ARE GIVEN HERE
Typology: Summaries
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Define a class taximeter having the following description: Data members/instance variables int taxino - to store taxi number String name - to store passenger's name int km - to store number of kilometres travelled Member functions: taximeter() -- constructor to initialize taxino to 0, name to "" and km to 0. input() - to store taxino, name, km calculate() - to calculate bill for a customer according to given conditions kilometers travelled(km) Rate/km Less than 1 km: Rs 25 1 km to 6 km: Rs 20 Greater than 6 km and upto 12 km: Rs 18 Greater than 12 km and upto 18 km: Rs 15 Greater than 18 km: Rs 10 display()- To display the details in the following format Taxino Name Kilometres travelled Bill amount
import java.io.; class taximeter { int taxino,km; String name; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); taximeter() { taxino=0; km=0; name=""; } public void input()throws Exception { System.out.println("Enter the name:"); name=br.readLine(); System.out.println("Enter the taxi number:"); taxino=Integer.parseInt(br.readLine()); System.out.println("Enter the km travelled:"); km=Integer.parseInt(br.readLine()); } public void calculate() { System.out.println("Taxino Name Kilometres travelled Bill amount "); System.out.print(taxino); System.out.print(" "+name); System.out.print(" "+km); if(km<1 o:p="o:p"> System.out.print(" Rs. 25"); else if(km>=1 && km<=6) System.out.print(" Rs."+(20km)); else if(km>6 && km<=12) System.out.print(" Rs."+(18*km)); else if(km>12 && km<=18)
System.out.print(" Rs."+(15km)); else if(km>18 ) System.out.print(" Rs."+(10km)); } public static void main(String args[])throws Exception { taximeter ob=new taximeter(); ob.input(); ob.calculate(); } }
import java.util.; class movieMagic{ int year; String title; float rating; public movieMagic(){ year = 0; title = ""; rating = 0; } public void accept(){ Scanner sc = new Scanner( System.in ); System.out.print("Enter title: "); title = sc.nextLine(); System.out.print("Enter year: "); year = sc.nextInt(); System.out.print("Enter rating: "); rating = sc.nextFloat(); } public void display(){ String message = ""; System.out.print("Title: "+title); if( rating >= 0.0f && rating <= 2.0 ) message="Flop"; else if( rating >= 2.1f && rating <= 3.4 ) message="Semi-hit"; else if( rating >= 3.5f && rating <= 4.5 ) message="Hit"; else if( rating >= 0.0f && rating <= 2.0 ) message="Super Hit"; System.out.println("Result: "+ message ); } public static void main( String args[] ){ movieMagic obj = new movieMagic( ); obj.accept( ); obj.display( ); } }*
price = Double.parseDouble(br.readLine()); } void calculate() // calculate method { if(price <= 1000) { discount = price * 0.02; // 2% discount price } else if(price > 1000 && price <= 3000) // 10% discount price { discount = price * 0.1; } else { discount = price *.15; // 15% discount price } } void display() // display method { price = price - discount; System.out.println("\n\n Book Name :" + Bname); System.out.println("\n Price after discount :" + price); } public static void main(String args[]) throws IOException { // Object creation BookFair ob = new BookFair(); ob.input(); ob.calculate(); ob.display(); } }