How to model a PDDL case in Java - java

I'm trying to model a normal PDDL case ,as the logistics example, into a different programming language(java). I'm doing this to understand what are the advantages or disvantages in using PDDL.
This is the PDDL original example
https://github.com/pellierd/pddl4j/wiki/Logistics:-a-simple-running-example
My result is an easy sequential program, shown in the code. My target is to automatize the calculation to obtain a real combinatorial calculation, not a sequential one.
public class logistics {
private static boolean airplaneInUse = false;
private static boolean truckInUse = false;
private static String airport;
private static String place;
private static String city;
private static String pack1;
private static String pack2;
static int state = 0;
public static void main(String args[]) {
if(state == 0) {
start();
System.out.println("The city in the initial state is " + city + "\n");
System.out.println("The airport in the initial state is " + airport + "\n");
}
if(city == "London") {
load_plane();
System.out.println("pk1 and pk2 are on the plane" +"\n");
pack1 = "On Board";
pack2 = "On Board";
}
if(pack1 == "On Board" && pack2 == "On Board") {
fly();
System.out.println("The city after the flight is " + city + "\n");
System.out.println("The airport after the flight is " + airport + "\n");
}
if (city == "Paris") {
unload_plane();
System.out.println("pk1 and pk2 are unloaded from the plane " + "\n");
pack1 = "Unloaded";
pack2 = "Unloaded";
}
if (pack1 == "Unloaded" && pack2 == "Unloaded") {
load_truck();
System.out.println(pack1 + "\n");
System.out.println(pack2 + "\n");
}
if(pack1 == "pk1 On the truck" || pack2 == "pk2 On the truck") {
drive_truck();
System.out.println("Driving to the first place " + "\n");
System.out.println("Driving to the second place " + "\n");
}
if (truckInUse == true) {
unload_truck1();
System.out.println("pk1 delivered in the " + place + "\n");
unload_truck2();
System.out.println("pk2 delivered in the " + place + "\n");
}
}
public static void start() {
city = "London";
airport = "lhr";
return;
}
public static void load_plane() {
city = "London";
pack1 = " pk1 On board";
pack2 = " pk2 On board";
return;
}
public static void fly() {
city = "Paris";
airport = "cdg";
airplaneInUse = true;
return;
}
public static void unload_plane() {
pack1 = "Arrived in Paris";
pack2 = "Arrived in Paris";
airplaneInUse = false;
return;
}
public static void load_truck() {
pack1 = "pk1 On the truck";
pack2 = "pk2 On the truck";
return;
}
public static void drive_truck() {
truckInUse = true;
return;
}
public static void unload_truck1() {
truckInUse = false;
pack1 = "Arrived in South";
place = "South";
return;
}
public static void unload_truck2() {
truckInUse = false;
pack1 = "Arrived in North";
place = "North";
return;
}
}
How can I reach my target? How can I obtain a combinatorial calculation to solve the problem?

I think you are getting at it the wrong way around. Do not try to implement any if/else imperative logic. Declare your actions (aka operators), domain, problem and call a planner to solve it. If you do want to create the domain and problem without encoding it into PDDL and letting the planner (e.g. pddl4j) parse it, you can code it out in Java and hand it over as a coded domain and coded problem.
The structure of your code will be very similar as what you would have put into PDDL, so besides shaving off the parsing time and speeding up the solution time, I do not see much point doing it this way. If you do, keep reading...
See a code example how you call the planner via the pddl4j APIs: https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-6-searching-for-a-solution-plan
Now, normally, you would let the PDDL parser do the job: https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-5-parse-and-encode-the-pddl-domain-and-problem-files
...but if you want to code it out, you will need to declare your actions, domain and problem using the Op, Domain and Problem classes.
Then you call encode the Problem and call one of the planners in pddl4j as indicated in one of the tutorials (links I pasted above). Does this help?

Related

How to improve a cumbersome comparison of 2 objects' fields

We have a program that compares thousands of pairs of Students by checking each field of the Student and counting the diffs:
class Student{
String name;
String address;
String biologyCourse;
.....
// about 100 other fields
}
And the counter POJO class:
class Counters{
long bothStudentsHaveName;
long onlyLeftHasName;
long onlyRightHasName;
......
// number of fields in Student * 3 (both, only left, only right)
}
Our compare function accepts 2 students plus the counters object and needs to scan the fields and update the relevant counters:
public void compareStudents(Student left, Student right, Counters counters){
if (!StringUtils.isEmpty(left.name) && !StringUtils.isEmpty(right.name) ){
counters.bothStudentsHaveName++;
} else if (StringUtils.isEmpty(left.name) && !StringUtils.isEmpty(right.name)){
counters.onlyRightHasName++;
} else if (!StringUtils.isEmpty(left.name) && StringUtils.isEmpty(right.name))){
counters.onlyLeftHasName++;
}
/// and now??
}
At this point, we can add 100s more triplets of if/else like the above - but we believe there should be a much easier way to do that.
Reflection can be an option or maybe X dimensions arrays, but can we somehow write the code so the comparison and counting will be much more generic?
I have solved your problem with one single loop. But here I'm assuming that naming convention for all the fields will be the same as described in your question. Here I am dynamically accessing the Student fields and updating Counter fields accordingly. Here is the complete solution:
Solution Class:
public class Solution {
public void compareStudents(Student left, Student right, Counter counter) throws Exception {
for (Field field : Student.class.getDeclaredFields()) {
Object leftValue = field.get(left);
Object rightValue = field.get(right);
String fieldName = field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
if(leftValue != null && rightValue != null) {
Field counterField = Counter.class.getDeclaredField("bothStudentsHave" + fieldName);
counterField.set(counter, (long) counterField.get(counter) + 1);
} else if (leftValue != null) {
Field counterField = Counter.class.getDeclaredField("onlyLeftHas" + fieldName);
counterField.set(counter, (long) counterField.get(counter) + 1);
} else if (rightValue != null) {
Field counterField = Counter.class.getDeclaredField("onlyRightHas" + fieldName);
counterField.set(counter, (long) counterField.get(counter) + 1);
}
}
}
}
Student Class:
class Student {
String name;
String address;
String biologyCourse;
}
Counter Class:
class Counter {
// name
long bothStudentsHaveName;
long onlyLeftHasName;
long onlyRightHasName;
// address
long bothStudentsHaveAddress;
long onlyLeftHasAddress;
long onlyRightHasAddress;
// biologyCourse
long bothStudentsHaveBiologyCourse;
long onlyLeftHasBiologyCourse;
long onlyRightHasBiologyCourse;
// ... and so on
#Override
public String toString() {
return "Counter{" + "\n" +
"\tbothStudentsHaveName = " + bothStudentsHaveName + "\n" +
"\t, onlyLeftHasName = " + onlyLeftHasName + "\n" +
"\t, onlyRightHasName = " + onlyRightHasName + "\n" +
"\t, bothStudentsHaveAddress = " + bothStudentsHaveAddress + "\n" +
"\t, onlyLeftHasAddress = " + onlyLeftHasAddress + "\n" +
"\t, onlyRightHasAddress = " + onlyRightHasAddress + "\n" +
"\t, bothStudentsHaveBiologyCourse = " + bothStudentsHaveBiologyCourse + "\n" +
"\t, onlyLeftHasBiologyCourse = " + onlyLeftHasBiologyCourse + "\n" +
"\t, onlyRightHasBiologyCourse = " + onlyRightHasBiologyCourse + "\n" +
'}';
}
}
Tester Class:
public class Tester {
public static void main(String[] args) throws Exception {
// Creating Dummy Variables
Student student1 = new Student();
student1.name = "Test";
student1.biologyCourse = "Yes";
Student student2 = new Student();
student2.name = "Test1";
student2.address = "abc street";
Counter counter = new Counter();
// Comparing Students
Solution solution = new Solution();
solution.compareStudents(student1, student2, counter);
// Printing Counter
System.out.println(counter);
}
}
Output:
Counter{
bothStudentsHaveName = 1
, onlyLeftHasName = 0
, onlyRightHasName = 0
, bothStudentsHaveAddress = 0
, onlyLeftHasAddress = 0
, onlyRightHasAddress = 1
, bothStudentsHaveBiologyCourse = 0
, onlyLeftHasBiologyCourse = 1
, onlyRightHasBiologyCourse = 0
}
If you keep repreating the same basic pattern of fields, then consider extracting that into a class. For example introduce a FieldComparison class that looks a little like this:
public class FieldComparisonCounter {
public int bothHave;
public int onlyLeftHas;
public int onlyRightHas;
// constructor, getters, setters left as an exercise for the reader
}
Then have a Map<String,FieldComparisonCounter> counters somewhere and a method like this:
public void compareField(String fieldName, String leftValue, String rightValue) {
FieldComparisonCounter counter = counters.get(fieldName);
if (counter == null) {
counter = new FieldComparisonCounter();
counters.put(fieldName, counter);
}
boolean leftHas = !StringUtils.isEmpty(leftValue);
boolean rightHas = !StringUtils.isEmpty(rightValue);
if (leftHas && rightHas) {
counter.bothHave++;
} else if (leftHas) {
counter.onlyLeftHas++;
} else if (rightHas) {
counter.onlyRightHas++;
}
}
Then adding a new field comparison is as simple as calling
compareField("name", left.name, right.name);

Overlapping classes under the same package in java

I am learning Java on my own, i came a cross this interesting example and i found it difficult to understand it.
What i want to know is, what is this called in Java when you have several classes under the same package all of them are Overlapping. Please take a look at the example below ? Note that none of the classes use implements, interface, abstract, extends etc...
And is it possible to find more of these examples ?
class Flightplan
public class Flightplan {
String type;
int seat;
String from;
String to;
// Other local variables, style captain ...
Person[] passenger;
int counter = 0;
Flightplan (String t, int s, String startPlace, String d) {
type = t;
seat = s;
passenger = new Person [s-1]; // kapten tar ett säte
// Captain takes a seat
from = startPlace;
to = d;
}
void book (Person p, String f, String t) {
if (f.equals(from) && t.equals(to)) {
passenger[counter] = p;
to = t;
counter++;
}
else System.out.println(p.name + " try to book a wrong flight !");
}
void flyg() {
System.out.println("On the plane " + this.typ + " reser");
for (int i = 0; i < passenger.length && passenger[i] != null; i++) {
System.out.println(passenger[i].name + ", ");
}
System.out.println("\n");
from = to;
}
}
class Person
public class Person {
String name;
String from;
String to;
String stopover;
int bags;
Flightplan flight;
Person (String n, String f, String m, String t, int v) {
name = n;
from = f;
stopover = m; // Only one stopover is approved, otherwise we would enter this as an array
to = t;
bags = v;
}
void boardNextLeg(Flightplan plan) {
flight = plan;
// Function bar for a stopover due. if-kit building
if (!stopover.equals(null) && flight.from.equals(this.from) && flight.to.equals(this.stopover)) {
System.out.print(this.name + " is now in between");
System.out.println(from + " and " + stopover);
flight.book(this, from, stopover);
}
else if (flight.from.equals(this.from) && flight.to.equals(this.to)) {
System.out.println(from + " och " + to);
flight.book(this, from, to);
}
else System.out.println(this.name + " could not be booked on a flight");
}
}
What is this called in Java when you have
several classes under the same package all of them are Overlapping ?
This is NOT overlapping, rather this is called circular dependency because your Flightplan and Person are dependent on each other, which is bad design and poorly developed.
Basically Circular Dependencies cause lots of issues (like OutofMemoryError) if not properly used, so they should be avoided in between the classes/packages.
You can look here for more details on circular dependencies.
By overlapping you mean that they have member variables with the same names? Each class has a different list of member variables, and one class presents no restrictions to another class.
I think this is called "Several classes that each deal with similar data values"

Why don't I get a calclatefee result? Is my Array value overriding my overridden method? [duplicate]

This question already has answers here:
Having inheritance and polymorphism issues with Java
(2 answers)
Closed 6 years ago.
I am trying to output calclatefee of $2 per day after 3 days. I have switched things around and I am left at this which looks a little sloppy. This Array is also making me take the confusing way.
public class Movie {
String rating;
String title;
int id;
int rentTime;
public String setrating() {
return rating;
}
public void rating(String getrating) {
rating = getrating;
}
public int setid() {
return id;
}
public void id(int agetid) {
id = agetid;
}
public String settitle() {
return title;
}
public void title(String gettitle) {
title = gettitle;
}
public int setfees() {
return rentTime;
}
public void fees(int getrentTime) {
rentTime = getrentTime;
}
public Movie() {
title = " ";
rating = " ";
id = 0;
rentTime = 0;
System.out.println("default constructor");
}
public Movie(String title, String rating, int id, int rentTime) {
title = " not overridden ";
rating = " NR ";
id = 0;
rentTime = 0;
System.out.println("Overloaded -" + title + rating + id + rentTime);
}
public static void main(String[] args) {
Movie[] Array = {
new Action(" The 100", " pg-13", 105, 7, 3),
new Comedy(" Supernatural", " pg-13", 5, 2, 0),
new Drama(" Lost 2", " R", 9, 2, 0) };
for (int x = 0; x < Array.length; x++) {
// System.out.println(x);
System.out.println(Array[x].toString());
}
}
}
public abstract class Action extends Movie {
protected double latecost;
protected double latefees = 3;
public Action(String gettitle, String getrating, int getid, int getrentTime, double latecost) {
super(gettitle, getrating, getid, getrentTime);
title = gettitle;
rating = getrating;
id = getid;
rentTime = getrentTime;
latecost = latefees;
System.out.println("Overridden " + title + rating + " " + id + " " + " " + rentTime + " "
+ latecost);
}
public double calclatefees(double latecost, double rentTime) {
if (rentTime > 3)
latefees = ((rentTime - 3) * latecost);
return latefees;
}
#Override
public String toString() {
String x = "\nMovie: " + title + " is rated " + rating + "\nMovie ID number: " + id
+ " and the late fee for action movies is $" + latecost + "\n";
return x;
}
protected void finalize() throws Throwable {
try {
System.out.println("Finalize method");
} finally {
super.finalize();
}
}
public void dispose() {
System.out.println(" dispose method");
}
}
Problems:
There's no calclatefee method to override in the parent class. If you want a child class to override method, it must be present in the parent class, at least as an abstract method (if the parent is abstract or is an interface).
You never call your calclatefee method anywhere, so you shouldn't expect to ever see its result in your output.
Your child class, Action, is abstract -- isn't that backwards? Most often its the parent class that's abstract, so why are you structuring it this way? And as written your main method shouldn't compile since you seem to be trying to create an instance of an abstract class.
Your class overrides the finalize() method, something that is generally not recommended. Fortunately your override doesn't really do anything other than output to the standard out and then call the super's method, but still, why risk it?
Side issues
Your code does not follow Java naming conventions. Variable names should all begin with a lower letter while class names with an upper case letter. Learning this and following this will allow us to better understand your code, and would allow you to better understand the code of others.
You will want to try to improve the formatting of your code that you post in here and your code in general. Good formatting including using an indentation style that is uniform and consistent will help others (us!) to better understand your code, and more importantly, it will help you to better understand your code and thus fix your own bugs. Also it shows that you're willing to put in extra effort to make it easier for the volunteers here to help you, and that effort is much appreciated. I took the liberty of trying to fix this for you.

How would I store the health values and run again until either player health == 0 or enemy health == 0

What would be the best way for me to code the the actual attack / defend between the two characters and how would I store the health value so that re attacks could be stored until either player health or enemy health reached 0, and then declare the victor. This is my first ever attempt at any kind programming after self teaching from various sources, please also give me feed back on any improvement I could make, I'm sure there will be many.
Thank you in advance.
:-)
package test;
public class BattleClass {
public static void main(String[] args) {
PlayerStats ps = new PlayerStats();
EnemyStats es = new EnemyStats();
int eh = es.getEnemyHealth();
int ph = ps.getPlayerHealth();
ps.PlayerAttackDefend();
es.AttackDefend();
System.out.println("You chose to " + ps.getpInput() + " and rolled "
+ ps.getPlayerRoll());
System.out.println("The enemy chose to " + es.getEaod()
+ " and rolled " + es.getEnemyRoll() + ".");
if (ps.getpInput().equals("Attack")) {
if (es.getEaod().equals("Attack")) {
System.out
.println("YOUR SWORDS BOUNCE OFF EACHOUTHERS... TRY AGAIN!");
System.exit(0);
}
if (es.getEaod().equals("Defend")) {
if (ps.getPlayerRoll() > es.getEnemyRoll())
eh -= ps.getPlayerRoll() - es.getEnemyRoll();
System.out.println("Enemy Health is " + eh);
}
}
if (ps.getpInput().equals("Defend")) {
if (es.getEaod().equals("Defend")) {
System.out
.println("YOUR SHIELDS BOUNCE OFF EACHOTHERS... TRY AGAIN!");
System.exit(0);
}
}
if (es.getEaod().equals("Attack")) {
if (es.getEnemyRoll() > ps.getPlayerRoll())
ph -= es.getEnemyRoll() - ps.getPlayerRoll();
System.out.println("Your Health is " + ph);
}
}
}
package test;
import java.util.Random;
import java.util.Scanner;
public class PlayerStats {
static Scanner paod = new Scanner(System.in);
//Players initial health value.
private int playerHealth = 10;
//RNG for attack value / defence value using dice as object.
private int playerRoll = new Random().nextInt(6) + 1;
private String pInput;
//Method for selecting Attack or Defence.
public void PlayerAttackDefend() {
System.out.println("Do you want to Attack or Defend?");
System.out.println("a = Attack / d = Defend");
//Player selects attack or defend.
String userInput = paod.nextLine();
if (userInput.equals("a")) {
pInput = "Attack";
}
if (userInput.equals("d")) {
pInput = "Defend";
}
}
public static Scanner getPaod() {
return paod;
}
public int getPlayerHealth() {
return playerHealth;
}
public int getPlayerRoll() {
return playerRoll;
}
public String getpInput() {
return pInput;
}
public static void setPaod(Scanner paod) {
PlayerStats.paod = paod;
}
public void setPlayerHealth(int playerHealth) {
this.playerHealth = playerHealth;
}
public void setPlayerRoll(int playerRoll) {
this.playerRoll = playerRoll;
}
public void setpInput(String pInput) {
this.pInput = pInput;
}
}
package test;
import java.util.Random;
public class EnemyStats {
//Enemy initial health value.
private int enemyHealth = 10;
//RNG for attack value / defence value using dice as object.
private static int enemyRoll = new Random().nextInt(6) + 1;
//RNG for enemy decision to Attack or Defend.
private static int eAttackDefend = new Random().nextInt(2) + 1;
//Used for returning attack or defend string.
private static String eaod;
//Attack or Defend method.
public void AttackDefend() {
if (eAttackDefend == 1) {
eaod = "Attack";
} else {
eaod = "Defend";
}
}
public int getEnemyHealth() {
return enemyHealth;
}
public int getEnemyRoll() {
return enemyRoll;
}
public int geteAttackDefend() {
return eAttackDefend;
}
public String getEaod() {
return eaod;
}
public void setEnemyHealth(int enemyHealth) {
this.enemyHealth = enemyHealth;
}
public void setEnemyRoll(int enemyRoll) {
EnemyStats.enemyRoll = enemyRoll;
}
public void seteAttackDefend(int eAttackDefend) {
EnemyStats.eAttackDefend = eAttackDefend;
}
public void setEaod(String eaod) {
EnemyStats.eaod = eaod;
}
}
An easy way would to be to set maxHp and actualHp values, if you want to be able to "heal".
If you just decrease until one is dead, you can just decrease the actual health variable you already have.
You might wanna take a look at Inheritance in general, as you have a lot of duplicate code.
In general, just make a loop
while(ps.getHealth() > 0 && es.getHealth() > 0) {
// your battle code
}
you might want to remove the System.exit(0) calls, as they terminate the program.
Add to the player/enemy a dealDamage(int damage) method to actually be able to reduce their health
The health values should be in the objects, and you should not need to store them in your BattleClass.
I could give you the short answer but I guess you get more out of a detailed explanation :-)
You want to run your code "until either player health or enemy health reached 0" so you need a loop.
In java you have 3 kinds of loops:
The for loop
for(int i=1;i<=3;i++) System.out.println("Hello Musketeer Nr. "+i);
The most elaborate loop, the for loop consists of three parts, the initialization, the condition, and the afterthought. While the for loop can be used differently, it is mostly is used in the fashion shown here, that is, you have a counter variable whose value you need somehow.
If you don't need the counter variable value, you can use the short form with collections and arrays:
for(Person p: persons) System.out.println("Hello, "+person.getName()+"!");
The while loop
The second most commonly used (at least by me) loop, it has an initial condition and iterates, as long as it is true.
while(ph>0&&eh>0)
{
...
}
As you see, it fits your problem very well. For completeness, I will however describe the third loop which is the
do-while loop
do
{
...
}
while(ph>0&&eh>0)
You use this loop like the while loop but if you want to have at least one run through.
Other Remarks
Why have two classes PlayerStats and EnemyStats in combat system (they both seem to have the same actions and values) ? You could just have:
Stats playerStats=new Stats();
Stats enemyStats=new Stats();

Playlist class music database

I'm writing a simple music database and ATM I'm trying to create a playlist class which will let the user organise their music (4 tracks previously entered into the database class) into a playlist of 3 songs.
After the user selects a song to be put into the playlist, the method is meant to search for the closest free slot in the newplaylist and place the Song variables (artist, name, duration & filesize) inside.
At the moment i am receiving this;
Entering the playlist tool...
Hello, welcome to the playlist builder!
Please select a track to add to the new playlist from the database below(using keys 1-4)
Slot 1:Trees:Breeze:2.34:128
1
Error: there is no free space in the database
Slot A : Song#3a1ec6
Slot B : Song#1ba6076
Slot C : Song#112e7f7
MENU
0 EXIT
1 IMPORT TRACK
2 SHOW ALL
3 Build a playlist(requires atleast 1 track in database)
Am I right in guessing that what is being returned is the reference to the location of the variables and not the variables themselves?
The code for Playlist.class is;
public class Playlist {
Song songDataPlay = new Song();
static UserInterface UI = new UserInterface();
static Song playlisttrackA = new Song();
static Song playlisttrackB = new Song();
static Song playlisttrackC = new Song();
private int MAX_TIME;
private double totalSize;
private double totalTIme;
String playlistClassArtist, playlistClassName;
double playlistClassDuration;
int playlistClassFileSize;
static String playlistArtist;
static String playlistName;
static double playlistDuration;
static int playlistFileSize;
static Song newplaySong;
static Song newSong;
static Song carryfromuserintoplaylist = UI.newPlaylistSongIN;
public void playlistObject(Song a, Song b, Song c) {
this.playlisttrackA = a;
this.playlisttrackB = b;
this.playlisttrackC = c;
}
public static void playlistAllocation() {
newSong = UI.newPlaylistSongIN;
Playlist plu = new Playlist();
SongDatabase SD = new SongDatabase();
Song newSong = carryfromuserintoplaylist;
if (playlisttrackA.songfileSize == 0) {
setSongA(newplaySong);
System.out.println("Slot A : " + playlisttrackA);
System.out.println("Slot B : " + playlisttrackB);
System.out.println("Slot C : " + playlisttrackC);
newplaySong = newSong;
} else if (playlisttrackB.songfileSize == 0) {
setSongB(newplaySong);
System.out.println("Slot A : " + playlisttrackA);
System.out.println("Slot B : " + playlisttrackB);
System.out.println("Slot C : " + playlisttrackC);
newplaySong = newSong;
} else if (playlisttrackC.songfileSize == 0) {
setSongC(newplaySong);
System.out.println("Slot A : " + playlisttrackA);
System.out.println("Slot B : " + playlisttrackB);
System.out.println("Slot C : " + playlisttrackC);
newplaySong = newSong;
} else {
System.out.println("Error: there is no free space in the database");
System.out.println("Slot A : " + playlisttrackA);
System.out.println("Slot B : " + playlisttrackB);
System.out.println("Slot C : " + playlisttrackC);
}
}
public static void setSongA(Song newSong) {
playlisttrackA = newplaySong;
playlisttrackA.songartist = newplaySong.songartist;
playlisttrackA.songname = newplaySong.songname;
playlisttrackA.songduration = newplaySong.songduration;
playlisttrackA.songfileSize = newplaySong.songfileSize;
}
public Song getSongA() {
return (playlisttrackA);
}
public static void setSongB(Song newSong) {
playlisttrackB = newplaySong;
playlisttrackB.songartist = newplaySong.songartist;
playlisttrackB.songname = newplaySong.songname;
playlisttrackB.songduration = newplaySong.songduration;
playlisttrackB.songfileSize = newplaySong.songfileSize;
}
public Song getSongB() {
return (playlisttrackB);
}
public static void setSongC(Song newSongC) {
playlisttrackC = newplaySong;
playlisttrackC.songartist = newplaySong.songartist;
playlisttrackC.songname = newplaySong.songname;
playlisttrackC.songduration = newplaySong.songduration;
playlisttrackC.songfileSize = newplaySong.songfileSize;
}
public Song getSongC() {
return (playlisttrackC);
}
public String returnPlaylist() {
if (playlisttrackA.songfileSize == 0 && playlisttrackB.songfileSize == 0 && playlisttrackC.songfileSize == 0) {
return ("Error ; No new playlists have been added.");
} else if (playlisttrackB.songfileSize == 0 && playlisttrackC.songfileSize == 0) {
return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + " to slot A in the new playlist");
} else if (newplaySong.songfileSize == 0) {
return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + " to slot B in the new playlist");
} else {
return ("You have imported:" + newplaySong.songname + " By " + newplaySong.songartist + " to slot C in the new playlist");
}
}
}
Any help would be great thanks,
System.out.println("Slot A : "+playlisttrackA); this calls the toString() method of Song (which is derived from Object). By default it prints the hash code of an object.
You should better print playlisttrackA.songname if I understand your code right.

Categories

Resources