Question: must be in java: Problem 2: We are going to create an array of playlist that hold songs. Create a class named Song. Create 3
must be in java:
Problem 2: We are going to create an array of playlist that hold songs.
Create a class named Song.
Create 3 instance variables, title, artist and length;
Create a constructor which initializes the instance variables. It will have 3 arguments.
Create 3 methods.
Create a getTitle method which should return a title.
Create a getArtist method which should return an artist.
Create a getLength method which should return a length.
Create a call named SongTester.
Import Scanner;
Create a Scanner object.
Create an array of type Song. It should hold 5 songs and be called playlist.
In a loop:
Ask the user to enter the name of the song and assign it to name.
Ask the user to enter the artist of the song and assign it to artist.
Ask the user to enter the length of the song and assign it to length.
Create a Song object using the user input.
Add the object to playlist.
Create a variable named playListLength.
Create a second loop
Get the length of each song in the playlist array
Add the length to playListLength.
Print the length of the playlist using words to describe the output.
the code i have:
public class Song { String title; String artist; int length; public Song(String title,String artist,int length) { this.title = title; this.artist = artist; this.length = length; } public String Title() { //getTitle method to return title return title; } public String Artist() { return artist; } public int Length() { //getLength method return length; } }
tester:
import java.util.Scanner; public class SongTester { public static void main(String[] args) { //this is the main method List
if (number % 100 < 20) { current = numNames[number % 100]; number /= 100; } else { current = numNames[number % 10]; number /= 10;
current = tensNames[number % 10] + current; number /= 10; } if (number == 0) return current; return numNames[number] + " hundred" + current; } public static String convert(int number) { if (number == 0) { return "zero"; } String prefix = ""; if (number < 0) { number = -number; prefix = "negative"; } String current = ""; int place = 0; do { int n = number % 1000; if (n != 0){ String s = convertLessThanOneThousand(n); current = s + specialNames[place] + current; } place++; number /= 1000; } while (number > 0); return (prefix + current).trim(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
