Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oopMidAssignment;
- //IT19113982
- //M.R.M Rikas
- import java.util.Scanner;
- import java.util.InputMismatchException;
- import java.util.Random;
- abstract class User {
- protected String name;
- protected String email;
- //DEFAULT CONSTRUCTORS
- public User() {
- }
- //OVERLOAD CONSTRUCTORS
- public User(String name, String email) {
- this.name = name;
- this.email = email;
- }
- //OVERLOAD CONSTRUCTORS
- public User(User NewUser){
- this.name= NewUser.name;
- this.email = NewUser.email;
- }
- //ABSTRACT METHOD
- abstract void printDetails();
- }
- class Operators extends User implements Calculations {
- protected int employeeNumber;
- protected String designation;
- //OVERLOAD CONSTRUCTOR
- public Operators(String name,String email,int employeeNumber,String designation){
- super.name = name;
- super.email = email;
- this.employeeNumber = employeeNumber;
- this.designation = designation;
- }
- //Abstract Method
- public void printDetails(){
- System.out.println("Operator name is " + name);
- System.out.println("Operator email is " + email);
- System.out.println("Operator employee number is " + employeeNumber);
- System.out.println("Operator designation is " + designation);
- System.out.println("\n");
- }
- //INTERFACE METHOD (IMPLEMENTATION)
- public void calculateRevenue(Artists A1) {
- int NumberOfDownloads = 0;
- Scanner D = new Scanner(System.in);
- //EXCEPTION
- try {
- System.out.println("Enter the number of downloads :");
- NumberOfDownloads = D.nextInt();
- }
- catch (InputMismatchException n){
- System.out.println("InputMismatchException Exception!");
- System.out.println("Programme terminated !");
- System.exit(0);//TERMINATE JVM
- }
- double revenue;
- double average = 0;
- //EXCEPTION
- try {
- for (int i=0;i<=A1.numOfSongs-1;i++) {
- for(int j=0;j<=0;j++) {
- String X;
- X=A1.song[i][j+1];
- average=average+Integer.parseInt(X);//CONVERT STRING TO INTEGER
- }
- }
- }catch(ArrayIndexOutOfBoundsException e){
- System.out.print("Array Index Out Of Bounds!");
- }
- average=average/5;
- revenue=average*NumberOfDownloads;
- System.out.println("Artist : "+A1.name);
- System.out.println("Album Revenue is LKR "+revenue);
- }
- }
- class Artists extends User {
- String genre;
- int numOfSongs;
- //STRING ARRAY
- String song[][] = new String[5][2];
- //OVERLOAD CONSTRUCTOR
- public Artists(String name,String email,String genre,int numOfSongs){
- super.name = name;
- super.email = email;
- this.genre = genre;
- this.numOfSongs = numOfSongs;
- }
- //STORE AND DISPLAY
- public void ArtistDetails() {
- int x, y;
- Scanner A1 = new Scanner(System.in);
- // FOR LOOP FOR STORE THE VALUES OF SONGS
- for (x = 0; x <=this.numOfSongs-1; x++) {
- for (y = 0; y <=0; y++) {
- //ADDING SONG NAMES TO ARRAY
- System.out.println("Enter Song : ");
- song[x][y] = A1.nextLine();
- //EXCEPTION
- try {
- //ADD SONG RATE TO THE ARRAY
- System.out.println("Enter Rate : ");
- String P1 = A1.nextLine();
- Integer.parseInt(P1);
- song[x][y+1]=P1;
- } catch (NumberFormatException e) {
- System.out.println("Number Format Exception! ");
- }
- }
- }
- }
- public void printDetails(){
- System.out.println("Artist name is " + name);
- System.out.println("Artist email is " + email);
- System.out.println("Artist music genre is " + genre);
- System.out.println("Number of songs is " + numOfSongs);
- System.out.println("Song list is : ");
- for (int i=0;i<=this.numOfSongs-1;i++) {
- for(int j=0;j<=0;j++) {
- System.out.println(song[i][j]+" "+song[i][j+1]);
- }
- }
- System.out.println("\n");
- }
- }
- interface Calculations {
- //DEFINE CALCULATE REVENUE METHOD
- void calculateRevenue(Artists A1);
- }
- public class PlayASong {
- public static void main(String[] args){
- //CREATE ARTISTS OBJECT
- Artists A1 = new Artists("Pablo Albo", "pablo@gmail.com", "POP",5);
- //CREATE OPERATORS OBJECT
- Operators O1 = new Operators( "Simon" , "simon@playsong.com", 123 , "Accountant");
- //CALLING METHODS
- A1.ArtistDetails();
- A1.printDetails();
- O1.printDetails();
- O1.calculateRevenue(A1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement