Created
May 20, 2021 09:40
-
-
Save Aroueterra/157462f87d7cb609bb5e6198ae32a3fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add class definitions below this line | |
import java.text.DecimalFormat; | |
import java.math.RoundingMode; | |
class Song{ | |
private String artist; | |
private String title; | |
private String album; | |
private int playCount; | |
private static final Double PAY_RATE = 0.001; | |
private Double moneyEarned; | |
public String getArtist(){ | |
return artist; | |
} | |
public String getTitle(){ | |
return title; | |
} | |
public String getAlbum(){ | |
return album; | |
} | |
public int getPlayCount(){ | |
return playCount; | |
} | |
public Double getPayRate(){ | |
return PAY_RATE; | |
} | |
public Double getMoneyEarned(){ | |
return moneyEarned; | |
} | |
// SETTER | |
public void setArtist(String v){ | |
artist = v; | |
} | |
public void setTitle(String v){ | |
title = v; | |
} | |
public void setAlbum(String v){ | |
album = v; | |
} | |
public void setPlayCount(int v){ | |
playCount = v; | |
} | |
public Song(String artist_, String title_, String album_, Double moneyEarned_){ | |
artist = artist_; | |
title = title_; | |
album = album_; | |
playCount = 0; | |
} | |
public void play(){ | |
setPlayCount(this.getPlayCount()+1); | |
moneyEarned = getPlayCount()*getPayRate(); | |
} | |
public Double fixFormat(Double d){ | |
DecimalFormat df = new DecimalFormat("#.###"); | |
df.setRoundingMode(RoundingMode.CEILING); | |
Double result = Double.valueOf(df.format(d)); | |
return result; | |
} | |
} | |
//add class definitions above this line | |
public class CodingExercise3 { | |
public static void main(String[] args) { | |
//add code below this line | |
Song mySong = new Song("led zeppelin", "ten years gone", "physical graffiti", 0.001); | |
mySong.play(); | |
System.out.println(mySong.getMoneyEarned()); | |
for (int i = 0; i < 10000; i++) { | |
mySong.play(); | |
} | |
System.out.println(mySong.getMoneyEarned()); | |
//add code above this line | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment