0% found this document useful (0 votes)
5 views

Assignment oop2

The document contains a Java program that defines a publication management system with classes for 'Publication', 'Book', and 'Magazine'. It allows users to input details about books and magazines, display them, and manage sales. The main class provides a menu-driven interface for users to interact with the system, including options to add books or magazines and exit the program.

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment oop2

The document contains a Java program that defines a publication management system with classes for 'Publication', 'Book', and 'Magazine'. It allows users to input details about books and magazines, display them, and manage sales. The main class provides a menu-driven interface for users to interact with the system, including options to add books or magazines and exit the program.

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;
class Publication
{
String title=null;
float price=0;
int copy=0;

void get()
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter the title : ");


title=sc.nextLine();

System.out.println("Enter price of 1: ");


price=sc.nextFloat();

System.out.println("Enter number of copies: ");


copy=sc.nextInt();
}

void display()
{
System.out.println("The title is: "+title);
System.out.println("The price is: "+price);
System.out.println("Number of copies are: "+copy);
}

void sale()
{
float tot;
int x;
int z;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of copies sold: ");
x=sc.nextInt();
tot=price*x;
z=copy-x;
System.out.println("The sale is: "+tot);
System.out.println("Available copies are: "+z);
}
}

class Book extends Publication


{
String author;

void books()
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter the author's name: ");


author=sc.nextLine();
System.out.println("Author of the book is: "+author);
}
}

class Magazine extends Publication


{
int ordqty;
String currentissue;

void magazines()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of copies sold: ");
ordqty=sc.nextInt();
}

void issue()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the date to be displayed in manner:
day/month/year");
currentissue=sc.nextLine();
System.out.println("The issue date of magazine is: ");
System.out.println(currentissue);
}
}

public class Main


{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Publication");
while(true)
{
System.out.println("Press according to your choice 1. Books 2. Magazines 3.
EXIT");
int ch;
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Book Operation");
Book b1 = new Book();
b1.get();
b1.books();
b1.display();
b1.sale();
break;

case 2:
System.out.println("Magazine Operation");
Magazine m1 = new Magazine();
m1.get();
m1.magazines();
m1.display();
m1.sale();
m1.issue();
break;

case 3:
System.out.println("Thank you");
System.exit(0);
break;
default:
System.out.println("Enter proper choice: ");
}
}
}
}

You might also like