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 song = new ArrayList(); Scanner in = new Scanner(System.in); int playlist[] = new int [5]; int playListLength = 5; System.out.println("Please Enter Song Title: "); String title = in.next(); System.out.println("Please Enter the Artist: "); String artist = in.next(); System.out.println("Please Enter the Length: "); int length = in.nextInt(); Song song2 = new Song(title, artist, length); song.add(song2); for(Song s : song){ playListLength=playListLength+s.Length(); } String numberToWord = convert(playListLength); System.out.println("Playlist Length : "+numberToWord); } private static final String[] specialNames = { "", " thousand", " million", " billion", " trillion", " quadrillion", " quintillion" }; private static final String[] tensNames = { "", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety" }; private static final String[] numNames = { "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen" }; private static String convertLessThanOneThousand(int number) { String current;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!