import java.util.
*;
class Publication {
String Title;
double Price;
int Copies;
/*Publication(){
Title=null;
Price=0.0;
Copies=0;
}*/
public int setcopies(int c) {
this.Copies = this.Copies-c;
return this.Copies;
}
public void setPrice(int c){
double TotalPrice=this.Price*c;
}
public void saleCopy(double totalPrice){
System.out.println("Total Publication sell: " + totalPrice);
}
}
class Book extends Publication {
String author;
int Bookno;
Book(){
Title=null;
Price=0.0;
Copies=0;
author=null;
}
Book(int index,String T, String a, double p, int c){
Bookno =index;
Title=T;
Price=p;
author=a;
Copies=c;
}
public double orderCopies(Book[] b){
double totalPrice=0.0;
int flag=0,ch;
Scanner scr = new Scanner(System.in);
do
{
System.out.println("Books available with us :");
for(int i=0; i<3; i++){
System.out.println(b[i].Bookno+ " \t " +b[i].Title+" \t "+b[i].author+ " \t " +
}
System.out.println("Enter the Book Number You want to Order");
int Bno = scr.nextInt();
int qty;
for(int i=0; i<3;i++)
{
if (b[i].Bookno==Bno){
System.out.println("Enter no of copies You want to Order");
qty=scr.nextInt();
if (b[i].Copies>=qty)
{
System.out.println("Copies Ordered Successfully");
totalPrice=totalPrice+ (b[i].Price*qty);
System.out.println("Total amount for "+b[i].Title+ " is :" + totalPrice);
System.out.println("No of Copies of "+ b[i].Title+ " left are " + b[i].setcop
flag=1;
break;
}
else
System.out.println(" Sorry Not sufficient Copies");
}
else
{
flag=0;
}
}
if (flag==0){
System.out.println("Book not Found");
}
System.out.println("Do you want to order more books? \n 1: Yes 2: No ");
ch=scr.nextInt();
}while(ch==1);
return totalPrice;
}
public void saleCopy(double totalPrice) {
System.out.println("Total Books sell: " +totalPrice );
}
}
class Magazine extends Publication{
int Mno;
int currentissued=0;
Magazine(){
Title=null;
Price=0.0;
Copies=0;
}
Magazine(int index,String T, double p, int c){
Mno=index;
Title=T;
Price=p;
Copies=c;
}
public double orderQty(Magazine[] m){
double totalPrice=0.0;
int flag=0;
Scanner scr = new Scanner(System.in);
System.out.println("Magazines available with us :");
for(int i=0; i<2; i++){
System.out.println(m[i].Mno+" \t "+m[i].Title+" \t "+ m[i].Price+ "\t " +m[i]
}
System.out.println("Enter the Magazine no You want to Order");
int index1 = scr.nextInt();
int qty;
for(int i=0; i<2;i++)
{
if (m[i].Mno==index1){
System.out.println("Enter no of copies You want to Order");
qty=scr.nextInt();
if (m[i].Copies>=qty)
{
System.out.println("Copies Ordered Successfully");
currentissued=qty;
System.out.println("Copies currently issued are : "+currentissued);
System.out.println("No of Copies of "+ m[i].Title+ " left are " + m[i].setcop
totalPrice=totalPrice+ (m[i].Price*qty);
flag=1;
break;
}
else {
System.out.println(" Sorry Not sufficient Copies");
}
}
else
{
flag=0;
}
}
if (flag==0){
System.out.println(" Magazine not Found");
}
return totalPrice;
}
public void saleCopy(double totalPrice) {
System.out.println("Total Magazine sell: " +totalPrice );
}
}
157
158 public class mainClass{
159 public static void main(String[] args)
160 {
161 String title, Bauthor;
162 int qty=0,i,ch,ch1;
163 double price, mp=0, p=0;
164
165 Book[] Booklist = new Book[3];
166 Booklist[0]=new Book(1,"Java", "Herbert Schildt", 900, 10 );
167 Booklist[1]=new Book(2,"Database", "Jason Price", 4000, 10 );
168 Booklist[2]=new Book(3,"Cloud", "Brian Spendolini", 4000, 10 );
169
170 Magazine[] m1=new Magazine[2];
171 m1[0]=new Magazine(1,"M1",300, 10 );
172 m1[1]=new Magazine(2,"M2",400, 10);
173
174 System.out.println(" Welcome to Oracle ");
175 do{
176 System.out.println("Enter the correct choice to order \n 1: Book 2: Magazi
177 Book obj1 = new Book();
178
179 Magazine m= new Magazine();
180 Scanner scr = new Scanner(System.in);
181 ch=scr.nextInt() ;
182 if (ch==1){
183 p=obj1.orderCopies(Booklist);
184 obj1.saleCopy(p);
185 }
186 else
187 {
188 mp=m.orderQty(m1);
189 m.saleCopy(mp);
190 }
191 System.out.println("\nDo you want to order something more? \n 1: Yes 2: No");
192 ch1=scr.nextInt();
193 }while(ch1==1);
194 Publication obj3 = new Publication();
obj3.saleCopy((p+mp));
}
}