You are on page 1of 4

Algorithm Class publication Start step 1: Create a class publication step 2: Declare methods writedata and constructors publication

step 3: initialise title as string and price as int End of class procedure publication(string,int) step 1: title = x, price = y End of procedure Procedure void writedata() step 1: print title step 2: print price End of procedure. Class book Start step 1: Create a class book step 2: Declare methods writedata and processdata and constructors book step 3: initialise nop , nob and value as int step 4: object ob1 of class publication is created End of class procedure book(int,int) step 1: nob = x, nop = y End of procedure Procedure void processdata() step 1: value = ob1.price * nob End of procedure Procedure void writedata() step 1: writedata function of class publication is called through ob1 step 2: print nop step 3: print nob step 4: print value End of procedure. Class tape Start step 1: Create a class tape step 2: Declare methods writedata and processdata and constructors tape step 3: initialise time , not and value as int step 4: object ob2 of class publication is created step 5: object ob3 of class book is created End of class procedure tape(int,int) step 1: not = x, time = y End of procedure Procedure void processdata() step 1: value = ob2.price * not End of procedure Procedure void writedata() step 1: writedata function of class tape is called through ob3 step 2: print not step 3: print time step 4: print value End of procedure. Class details Start step 1: Create a class details step 2: Declare a main method as void . End of class Procedure void main() step 1: object ob4 of class publication is created

step 2: object ob5 of class book created step 3: object ob6 of class tape is created step 4: a while loop begins till ans = 1 step 5: take input the title as t step 6: take input the price as p step 7: take input the no. of pages as nop step 8: take input the no. of books as nob step 9: take input the duration as d step 10: take input the no. of tapes as not step 11: take input the user's choice as ans step 12: t and p are passed to constructor publication() through ob4 step 13: nob and nop are passed to constructor book() through ob5 step 15: not and d are passed to constructor tape() through ob6 End of procedure. Source code import java.io.*; public class publication {//class starts String title; int price; publication() { title = ""; price = 0;//initializing variables } public publication(String x ,int y) { title = x; price = y; } public void writedata() { System.out.println("Title : " + title); System.out.println("Price : " + price); } }//class ends import java.io.*; public class book extends publication { int nop,nob,value; publication ob1 = new publication(); book() { nop = 0; nob = 0; value = 0;//initializing variables } public book(int x,int y) { nob = x; nop = y; } public void processdata() { value = ob1.price * nob; }

public void writedata() { ob1.writedata(); System.out.println("No. of pages : " + nop); System.out.println("No. of books : " + nob); System.out.println("Total value " + value); } }//class ends import java.io.*; public class tape extends publication { int time,not,value; publication ob2 = new publication(); book ob3 = new book(); tape() { not = 0; time = 0; value = 0;//initializing variables } public tape(int x,int y) { not = x; time = y; } public void processdata() { value = ob2.price * not; } public void writedata() { ob3.writedata(); System.out.println("No. of tapes : " + not); System.out.println("Duration : " + time); System.out.println("Total value " + value); } }//class ends import java.io.*; public class details {//class starts public void main()throws IOException {//main starts BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ; publication ob4 = new publication(); book ob5 = new book(); tape ob6 = new tape(); int ans= 1; while(ans == 1) { System.out.print("Enter title : "); String t = br.readLine(); System.out.print("Enter price : "); int p = Integer.parseInt(br.readLine()); System.out.print("Enter no. of pages : "); int nop = Integer.parseInt(br.readLine()); System.out.print("Enter no. of books : "); int nob = Integer.parseInt(br.readLine());

System.out.print("Enter duration : "); int d = Integer.parseInt(br.readLine()); System.out.print("Enter no. of tapes : "); int not = Integer.parseInt(br.readLine()); System.out.print("Any more ?(1 / 0) "); ans = Integer.parseInt(br.readLine()); ob4.publication(t,p); ob5.book(nob,nop); ob6.tape(not,d); } } }

Variable listing name type description title int stores title of book price int stores price of book not int stores no. of tapes nob int stores no. of books value int stores value of price of all books time int stores duration of each tape t String stores title input from user p int stores price input from user d int stores duration input from user

Function description name type function main void used to take input the title , price , no . of books , no. of tapes , duration of each tape and pass them to suitable methods to display suitable details writedata void used to print input the title , price , no . of books , no. of tapes , duration of each tape processdata void used to calculate total value of books and tapes

You might also like