Jump to content

Need some help with java

Sharif11
Go to solution Solved by jPak,

So, I've taken only a cursory look at the code and here's what I think might help:

 

You've declared getSaleOutcome inside of your makeOffer method -- this doesn't really work as you intended. Rather, declare getSaleOutcome elsewhere (somewhere inside of your PropertySale class but outside of any other method) and then call the method inside of your makeOffer method. Something like this:

public class PropertySale{

   ...

   some variables and methods

   ...

   getSaleOutcome(){

      print stuff here

   }

   ... more methods and stuff ...

   makeOffer(){

      ...your make offer definition is here...

      at the end of your method, you call getSaleOutcome()

   }

}

 

I really hope this helps and I wish you the best of luck; not everyone has the drive to learn to code on his own.

I,ve been practising java because I want to get good at it. I've been following a book and there's an exercise I'm stuck on.

How do I print a summary of the details (instance variables) as well as the current sale outcome for the current PropertySale to the screen?

Here's what I got so far:

public class PropertySale {

private String salesID;
private String propertyAddress;
private int reservePrice;
private int currentOffer;
private boolean saleStatus;

public PropertySale(String salesID, String propertyAddress, int reservePrice) {
this.salesID = salesID;
this.propertyAddress = propertyAddress;
this.reservePrice = reservePrice;
this.currentOffer = 0;
this.saleStatus = true;
}

public String getsalesID() {
return salesID;
}

public String getpropertyAddress() {
return propertyAddress;
}

public int getcurrentOffer() {
return currentOffer;
}

public boolean getsaleStatus() {
return saleStatus;
}

public boolean reserveMet() {

if (currentOffer >= reservePrice) {
return true;
} else {
return false;

}
}

public int getReservePrice() {
return reservePrice;
}

public void printSaleDetials() {
System.out.println("Sale id is: " + getsalesID());
System.out.println("Property address: " + getpropertyAddress());
System.out.println("Reserve Price: " + getReservePrice());
System.out.println("Current Offer: " + getcurrentOffer());
System.out.println("Sale Status: " + getsaleStatus());
System.out.println();
System.out.println();
}

public String getSaleOutcome(boolean saleOpen, boolean saleStatus) {
String returnValue = "";
if (saleOpen == true) {
returnValue = "ON SALE";
} else {

if (saleStatus == false) {
returnValue = "SOLD";
}
}
return returnValue;

}

public void setCurrentOffer(int offer) {
currentOffer = offer;
}

public void setSaleStatus(boolean status) {
saleStatus = status;
}

public boolean makeOffer(int offerPrice) {

if (currentOffer >= offerPrice) {
return false;
} else {
currentOffer = offerPrice;

if (reserveMet()) {
// print if true
// close sale
} else {
// print if false
}

return true;
}
}

public void getSaleOutcome() {
System.out.println(salesID);
System.out.println(propertyAddress);
System.out.println(reservePrice);
System.out.println(currentOffer);
System.out.println(saleStatus);

}
}

The last part is where I'm stuck. I know I'm wrong thats why I wanted some help.

It wants me to call a getSaleOutcome method which made me confused. Whats the best way to go about it?

Any help is Appreciated:)

Thanks

Link to comment
Share on other sites

Link to post
Share on other sites

So, I've taken only a cursory look at the code and here's what I think might help:

 

You've declared getSaleOutcome inside of your makeOffer method -- this doesn't really work as you intended. Rather, declare getSaleOutcome elsewhere (somewhere inside of your PropertySale class but outside of any other method) and then call the method inside of your makeOffer method. Something like this:

public class PropertySale{

   ...

   some variables and methods

   ...

   getSaleOutcome(){

      print stuff here

   }

   ... more methods and stuff ...

   makeOffer(){

      ...your make offer definition is here...

      at the end of your method, you call getSaleOutcome()

   }

}

 

I really hope this helps and I wish you the best of luck; not everyone has the drive to learn to code on his own.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Sorry I've taken so long to reply. Thank you very much for your help, it was very helpful :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×