Advertisement
Guest User

Milana

a guest
Mar 31st, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. package midq1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PlayASong {
  6.  
  7. public static void main(String[] args) {
  8. Artist artistob = new Artist("Pablo Albo","pablo@gmail.com","pop",2);
  9. artistob.enterSongDetails();
  10. artistob.printDetails();
  11. Operator operatorob = new Operator("Simon","simon@playasong.com","123","accountant");
  12. operatorob.printDetails();
  13. operatorob.calculateRevenue(artistob);
  14. }
  15. }
  16.  
  17. abstract class User{
  18. Scanner ob = new Scanner(System.in);
  19. protected String obname;
  20. protected String obemail;
  21.  
  22. public User(String pname, String pemail) {
  23. this.obname = pname;
  24. this.obemail = pemail;
  25. }
  26.  
  27. public User(User newUser) {
  28. this.obname = newUser.obname;
  29. this.obemail = newUser.obemail;
  30. }
  31.  
  32. abstract public void printDetails();
  33. }
  34.  
  35. interface Calculation{
  36. void calculateRevenue(Artist artistob);
  37. }
  38.  
  39. class Operator extends User implements Calculation{
  40.  
  41. private String obempNumber;
  42. private String objob;
  43.  
  44. public Operator(String nname, String nemail, String nempno, String njob) {
  45. super(nname, nemail);
  46. this.obempNumber = nempno;
  47. this.objob = njob;
  48. }
  49.  
  50. public void printDetails() {
  51. System.out.println("Operator name is "+ this.obname);
  52. System.out.println("Operator email is "+this.obemail);
  53. System.out.println("Operator employee number is "+this.obempNumber);
  54. System.out.println("Operator designation is "+this.objob);
  55. System.out.println("\n");
  56. }
  57.  
  58. public void calculateRevenue(Artist artistObject) {
  59. System.out.print("Enter number of downloads: ");
  60. int album = ob.nextInt();
  61. System.out.println("\n");
  62. System.out.println("Artist: "+artistObject.obname);
  63. double revenue = artistObject.calcRateAverage() * album;
  64. System.out.printf("Album revenue is LKR %.2f",revenue);
  65.  
  66. }
  67. }
  68.  
  69. class Artist extends User{
  70.  
  71. private String obgenre;
  72. private int obnumSongs;
  73. private String obsongList[][];
  74.  
  75. public Artist(String nname, String nemail, String ngenre, int nnumSongs) {
  76. super(nname, nemail);
  77. this.obgenre = ngenre;
  78. this.obnumSongs = nnumSongs;
  79. }
  80.  
  81. public void enterSongDetails() {
  82. String songrate = null;
  83. this.obsongList = new String[this.obnumSongs][2];
  84. for (int i = 0;i < obsongList.length; ++i) {
  85. System.out.println("Enter song:");
  86. this.obsongList[i][0] = ob.nextLine();
  87. try {
  88. System.out.println("Enter rate:");
  89. songrate = ob.nextLine();
  90. Double.parseDouble(songrate);
  91. } catch(NumberFormatException e) {
  92. System.out.print("Please enter a number for song rate: ");
  93. songrate = ob.nextLine();
  94. } finally {
  95. this.obsongList[i][1] = songrate;
  96. System.out.println("\n");
  97. }
  98. }
  99. }
  100.  
  101. public void printDetails() {
  102. System.out.println("Artist's name is "+this.obname);
  103. System.out.println("Artist's email is "+this.obemail);
  104. System.out.println("Artist's genre is "+this.obgenre);
  105. System.out.println("Number of songs is "+this.obnumSongs);
  106. System.out.println("Song list is:");
  107.  
  108. for (int c = 0;c < this.obnumSongs; ++c) {
  109. System.out.println(this.obsongList[c][0]+"\t"+this.obsongList[c][1]);
  110. }
  111. System.out.println("\n");
  112. }
  113. public double calcRateAverage() {
  114. double songavg = 0.00;
  115. for (int s = 0; s < obsongList.length; ++s) {
  116. songavg = songavg + Double.parseDouble(this.obsongList[s][1]);
  117. }
  118. songavg = songavg / obsongList.length;
  119. return songavg;
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement