SHARE
TWEET

Song Class

a guest Mar 25th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. public class Song {
  3.     //fields
  4.     private String title;
  5.     private String artist;
  6.     private int year;
  7.     private int rank;
  8.    
  9.     //constructor
  10.     public Song(String inputLine) {
  11.         Scanner inputScanner = new Scanner(inputLine.substring(0, inputLine.length()) + "\t").useDelimiter("\t");
  12.         year = inputScanner.nextInt();
  13.         rank = inputScanner.nextInt();
  14.         artist = inputScanner.next();
  15.         title = inputScanner.next();
  16.     }
  17.    
  18.     //getters
  19.     public String getTitle() {
  20.         return title;
  21.     }
  22.     public String getArtist() {
  23.         return artist;
  24.     }
  25.     public int getRank() {
  26.         return rank;
  27.     }
  28.     public int getYear() {
  29.         return year;
  30.     }
  31.    
  32.     //toString
  33.     public String toString() {
  34.         return String.format("%d\t%d\t %s by %s", rank, year, title, artist);
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top