Java Klase
Java Klase
-KLASE-
//
//
System.out.println(song.title);
}
//
System.out.println(song.title);
Test t = new Test();
//
//
t.testSettersAndGetters();
t.testConstructors();
t.testArrays();
}
}q
//
System.out.println(song.title);
Test t = new Test();
//
//
//
//
//
t.testSettersAndGetters();
t.testConstructors();
t.testArrays();
t.testLoops();
t.testScanner();
t.testNumberFormat();
}
return this.title + ", by " + this.author + ", a nice Rock song" + " from the South";
package test;
import java.util.Scanner;
import java.text.NumberFormat;
import
import
import
import
music.Album;
music.RockSong;
music.Song;
music.SouthernRockSong;
System.out.println(song.getTitle());
//
}
public void testConstructors() {
Song song = new Song("That's All Right", "Elvis Presley");
song.setTitle("That's All Right");
System.out.println(song.getTitle());
}
songs[0] = gloryDays;
songs[1] = dancingInTheDark;
songs[2] = hungryHeart;
bornInTheUSA.listSongs();
songs[0] = gloryDays;
songs[1] = dancingInTheDark;
songs[2] = hungryHeart;
bornInTheUSA.listSongs(true);
//
bornInTheUSA.listSongs(false);
song.setTitle(title);
System.out.println(song.getTitle());
double a = 45.234;
double b = 33.67;
System.out.println(a/b);
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(a/b));
song.showDefinition();
song.setYear(1954);
System.out.println(song);
System.out.println(aString);
System.out.println(aString.toUpperCase());
song1.append(song);
System.out.println(song1);
System.out.println(song1);
song1.delete(13, 34);
System.out.println(song1);
//
StringBuffer sb = "Arthur Crudup";
System.out.println(gloryDays);
SouthernRockSong whippingPost =
"humiliation", 2);
songs[0] = thatsAllRight;
songs[1] = purpleHaze;
songs[2] = whippingPost;
}
}
package main;
import test.Test;
public class Main {
//
System.out.println(song.title);
//
//
//
//
//
//
//
//
//
package music;
import java.util.ArrayList;
public class PlayList {
private ArrayList<Song> songs;
public PlayList(ArrayList<Song> songs) {
super();
this.songs = songs;
}
public PlayList() {
super();
songs = new ArrayList<Song>();
}
package music;
public class Album {
this.title = title;
this.author = author;
this.songs = songs;
public Album() {
System.out.println(songs[i].getTitle());
int i = 0;
if (loopType == true) {
if (i == 2) {
break;
System.out.println(songs[i].getTitle());
i++;
// i = i + 1;
} else {
do {
System.out.println(songs[i].getTitle());
i++;
this.title = title;
return this.title;
this.author = author;
return this.author;
this.songs = songs;
return this.songs;
}
}
package music;
public class EmptySetListException extends Exception {
public EmptySetListException() {
super();
// TODO Auto-generated constructor stub
}
public EmptySetListException(String arg0, Throwable arg1, boolean arg2,
boolean arg3) {
super(arg0, arg1, arg2, arg3);
// TODO Auto-generated constructor stub
}
public EmptySetListException(String arg0, Throwable arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
public EmptySetListException(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public EmptySetListException(Throwable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
package music;
import java.util.ArrayList;
public class PlayList implements SongList {
private ArrayList<Song> songs;
public PlayList(ArrayList<Song> songs) {
super();
this.songs = songs;
}
public PlayList() {
super();
songs = new ArrayList<Song>();
}
package music;
public class Song {
static {
year = 1955;
this.title = title;
this.author = author;
public Song() {
//
public boolean equals(Object obj) {
//
if (obj instanceof Song) {
//
Song s = (Song) obj;
//
if (this.title.equals(s.getTitle()) && this.author.equals(s.getAuthor())) {
//
return true;
//
} else {
//
return false;
//
}
//
}
//
return false;
//
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((author == null) ? 0 : author.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Song other = (Song) obj;
if (author == null) {
if (other.author != null)
return false;
} else if (!author.equals(other.author))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
this.title = title;
return this.title;
this.author = author;
return this.author;
this.year = year;
return this.year;
package music;
public class RockSong extends Song {
public static final String DEFINING_FEATURE = "Electric guitar";
private String meaning;
public RockSong() {
super();
// TODO Auto-generated constructor stub
}
public RockSong(String title, String author) {
super(title, author);
// TODO Auto-generated constructor stub
}
public RockSong(String title, String author, String meaning) {
super(title, author);
this.meaning = meaning;
}
package music;
import java.util.ArrayList;
public class SetList implements SongList {
private ArrayList<String> songs;
public SetList(ArrayList<String> songs) {
super();
this.songs = songs;
}
public SetList() {
super();
this.songs = new ArrayList<String>();
}
@Override
public void addSong(Song song) {
songs.add(song.getTitle());
}
@Override
public void removeSong(int i) {
songs.remove(i);
}
public void showSetList() {
System.out.println("Setlist:");
for (int i = 0; i < songs.size(); i++) {
System.out.println(songs.get(i));
}
}
public ArrayList<String> getSongs() {
return songs;
}
public void setSongs(ArrayList<String> songs) {
this.songs = songs;
}
}
package music;
public interface SongList {
public void addSong(Song song);
public void removeSong(int i);
}
package music;
public class SouthernRockSong extends RockSong {
private int noOfLeadGuitars;
public SouthernRockSong() {
super();
// TODO Auto-generated constructor stub
}
public SouthernRockSong(String title, String author, String meaning) {
super(title, author, meaning);
// TODO Auto-generated constructor stub
}
public SouthernRockSong(String title, String author, String meaning, int noOfLeadGuitars) {
super(title, author, meaning);
this.noOfLeadGuitars = noOfLeadGuitars;
// TODO Auto-generated constructor stub
}
return this.title + ", by " + this.author + ", a nice Rock song" + " from the South";
package test;
import java.util.Scanner;
import java.text.NumberFormat;
import
import
import
import
import
import
import
music.Album;
music.PlayList;
music.RockSong;
music.SetList;
music.Song;
music.SongList;
music.SouthernRockSong;
System.out.println(song.getTitle());
System.out.println(song.getTitle());
songs[0] = gloryDays;
songs[1] = dancingInTheDark;
songs[2] = hungryHeart;
bornInTheUSA.listSongs();
songs[0] = gloryDays;
songs[1] = dancingInTheDark;
songs[2] = hungryHeart;
bornInTheUSA.listSongs(true);
//
bornInTheUSA.listSongs(false);
song.setTitle(title);
System.out.println(song.getTitle());
double a = 45.234;
double b = 33.67;
System.out.println(a/b);
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(a/b));
song.showDefinition();
song.setYear(1954);
System.out.println(song);
System.out.println(aString);
System.out.println(aString.toUpperCase());
song1.append(song);
System.out.println(song1);
System.out.println(song1);
song1.delete(13, 34);
System.out.println(song1);
//
StringBuffer sb = "Arthur Crudup";
System.out.println(gloryDays);
SouthernRockSong whippingPost =
"humiliation", 2);
songs[0] = thatsAllRight;
songs[1] = purpleHaze;
songs[2] = whippingPost;
//
purpleHaze = thatsAllRight;
//
if (thatsAllRight == thatsAllRight1) {
//
System.out.println("They are the same!?!?");
//
} else {
//
System.out.println("No way.");
//
}
if (thatsAllRight.equals(thatsAllRight1)) {
} else {
System.out.println("No way.");
System.out.println();
String s1 = thatsAllRight.getTitle();
String s2 = thatsAllRight.getTitle();
if (s1 == s2) {
} else {
SouthernRockSong whippingPost =
"humiliation", 2);
playlist.addSong(thatsAllRight);
playlist.addSong(purpleHaze);
playlist.addSong(whippingPost);
playlist.showPlayList();
System.out.println();
playlist.removeSong(1);
playlist.showPlayList();
SouthernRockSong whippingPost =
"humiliation", 2);
playlist.addSong(thatsAllRight);
//
playlist.addSong(new Song("That's All Right", "Elvis Presley"));
playlist.addSong(purpleHaze);
playlist.addSong(whippingPost);
setlist.addSong(thatsAllRight);
setlist.addSong(purpleHaze);
setlist.addSong(whippingPost);
pl.showPlayList();
//
((PlayList) playlist).showPlayList();
System.out.println();
((SetList) setlist).showSetList();
}
}
package main;
import test.Test;
public class Main {
//
System.out.println(song.title);
t.testSettersAndGetters();
//
t.testConstructors();
//
t.testArrays();
//
t.testLoops();
//
t.testScanner();
//
t.testNumberFormat();
//
t.testStatic();
//
t.testStrings();
//
t.testToString();
//
t.testInheritance();
//
t.testEquals();
//
t.testLists();
//
t.testInterfaces();
t.testExceptions();
}
}