Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. package oopMidAssignment;
  2.  
  3. //IT19113982
  4. //M.R.M Rikas
  5.  
  6. import java.util.Scanner;
  7. import java.util.InputMismatchException;
  8. import java.util.Random;
  9.  
  10. abstract class User {
  11.  
  12. protected String name;
  13. protected String email;
  14.  
  15. //DEFAULT CONSTRUCTORS
  16. public User() {
  17.  
  18. }
  19.  
  20. //OVERLOAD CONSTRUCTORS
  21. public User(String name, String email) {
  22. this.name = name;
  23. this.email = email;
  24. }
  25. //OVERLOAD CONSTRUCTORS
  26. public User(User NewUser){
  27. this.name= NewUser.name;
  28. this.email = NewUser.email;
  29. }
  30.  
  31. //ABSTRACT METHOD
  32. abstract void printDetails();
  33. }
  34.  
  35.  
  36. class Operators extends User implements Calculations {
  37. protected int employeeNumber;
  38. protected String designation;
  39.  
  40. //OVERLOAD CONSTRUCTOR
  41. public Operators(String name,String email,int employeeNumber,String designation){
  42. super.name = name;
  43. super.email = email;
  44. this.employeeNumber = employeeNumber;
  45. this.designation = designation;
  46. }
  47.  
  48. //Abstract Method
  49. public void printDetails(){
  50. System.out.println("Operator name is " + name);
  51. System.out.println("Operator email is " + email);
  52. System.out.println("Operator employee number is " + employeeNumber);
  53. System.out.println("Operator designation is " + designation);
  54. System.out.println("\n");
  55. }
  56.  
  57. //INTERFACE METHOD (IMPLEMENTATION)
  58. public void calculateRevenue(Artists A1) {
  59. int NumberOfDownloads = 0;
  60. Scanner D = new Scanner(System.in);
  61.  
  62. //EXCEPTION
  63. try {
  64. System.out.println("Enter the number of downloads :");
  65. NumberOfDownloads = D.nextInt();
  66. }
  67. catch (InputMismatchException n){
  68. System.out.println("InputMismatchException Exception!");
  69. System.out.println("Programme terminated !");
  70. System.exit(0);//TERMINATE JVM
  71. }
  72.  
  73. double revenue;
  74. double average = 0;
  75.  
  76. //EXCEPTION
  77. try {
  78. for (int i=0;i<=A1.numOfSongs-1;i++) {
  79. for(int j=0;j<=0;j++) {
  80. String X;
  81. X=A1.song[i][j+1];
  82. average=average+Integer.parseInt(X);//CONVERT STRING TO INTEGER
  83. }
  84. }
  85. }catch(ArrayIndexOutOfBoundsException e){
  86. System.out.print("Array Index Out Of Bounds!");
  87. }
  88. average=average/5;
  89. revenue=average*NumberOfDownloads;
  90. System.out.println("Artist : "+A1.name);
  91. System.out.println("Album Revenue is LKR "+revenue);
  92. }
  93.  
  94.  
  95. }
  96.  
  97. class Artists extends User {
  98.  
  99.  
  100. String genre;
  101. int numOfSongs;
  102.  
  103. //STRING ARRAY
  104. String song[][] = new String[5][2];
  105.  
  106. //OVERLOAD CONSTRUCTOR
  107. public Artists(String name,String email,String genre,int numOfSongs){
  108. super.name = name;
  109. super.email = email;
  110. this.genre = genre;
  111. this.numOfSongs = numOfSongs;
  112. }
  113.  
  114. //STORE AND DISPLAY
  115. public void ArtistDetails() {
  116. int x, y;
  117. Scanner A1 = new Scanner(System.in);
  118. // FOR LOOP FOR STORE THE VALUES OF SONGS
  119. for (x = 0; x <=this.numOfSongs-1; x++) {
  120. for (y = 0; y <=0; y++) {
  121.  
  122. //ADDING SONG NAMES TO ARRAY
  123. System.out.println("Enter Song : ");
  124. song[x][y] = A1.nextLine();
  125.  
  126. //EXCEPTION
  127. try {
  128. //ADD SONG RATE TO THE ARRAY
  129. System.out.println("Enter Rate : ");
  130. String P1 = A1.nextLine();
  131. Integer.parseInt(P1);
  132. song[x][y+1]=P1;
  133.  
  134. } catch (NumberFormatException e) {
  135. System.out.println("Number Format Exception! ");
  136. }
  137. }
  138.  
  139. }
  140. }
  141. public void printDetails(){
  142. System.out.println("Artist name is " + name);
  143. System.out.println("Artist email is " + email);
  144. System.out.println("Artist music genre is " + genre);
  145. System.out.println("Number of songs is " + numOfSongs);
  146.  
  147. System.out.println("Song list is : ");
  148.  
  149. for (int i=0;i<=this.numOfSongs-1;i++) {
  150. for(int j=0;j<=0;j++) {
  151. System.out.println(song[i][j]+" "+song[i][j+1]);
  152. }
  153. }
  154. System.out.println("\n");
  155.  
  156. }
  157.  
  158. }
  159.  
  160. interface Calculations {
  161. //DEFINE CALCULATE REVENUE METHOD
  162. void calculateRevenue(Artists A1);
  163. }
  164.  
  165. public class PlayASong {
  166. public static void main(String[] args){
  167.  
  168. //CREATE ARTISTS OBJECT
  169. Artists A1 = new Artists("Pablo Albo", "pablo@gmail.com", "POP",5);
  170.  
  171. //CREATE OPERATORS OBJECT
  172. Operators O1 = new Operators( "Simon" , "simon@playsong.com", 123 , "Accountant");
  173.  
  174. //CALLING METHODS
  175. A1.ArtistDetails();
  176. A1.printDetails();
  177.  
  178. O1.printDetails();
  179. O1.calculateRevenue(A1);
  180.  
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement