missing return statement

Reply

Join Date: Mar 2006
Posts: 2
Reputation: gagirl14 is an unknown quantity at this point 
Solved Threads: 0
gagirl14 gagirl14 is offline Offline
Newbie Poster

missing return statement

 
0
  #1
Mar 29th, 2006
I don't know why I'm getting this return statement Please help. Error is in green

public class Card {

private int rank;
private int suit;

public Card()
{
suit = (int)Math.floor(Math.random() * (4-1) + 0.5) +4;
rank = (int)Math.floor(Math.random() * (14-2) + 0.5) +14;
}
public Card(int r, int s)
{
if (r>=2 && r<=14)
rank = r;
else rank = 14;

if (s>=1 && s<=4)
suit = s;
else suit = 4;
}
public int getSuit() //returns suit
{
return suit;
}
public int getRank() //return rank
{
return rank;
}

public boolean isHigher(Card c)
{
if (c.getRank() >rank){ //if Card is higher in rank return true
return true;
}
else
if (c.getRank() < rank){ //if Card is lower in rank return false
return false;
}
else
if (c.getRank() ==rank){ //if rank is equal then evaluate suit

if (c.getSuit() >suit){
return true;
}
else
if (c.getSuit() <suit){
return false;
}
}

I get error here }
public String toString()
{
String strRank = "";
String strSuit = "";

if (rank ==14){
strRank = "A";
}

else
if (rank ==13){
strRank = "K";
}
else
if (rank ==12){
strRank = "Q";
}
else
if (rank ==11){
strRank = "J";
}
else
if (rank ==10){
strRank = "10";
}
else
if (rank ==9){
strRank = "9";
}
else
if (rank ==8){
strRank = "8";
}
else
if (rank ==7){
strRank = "7";
}
else
if (rank ==6){
strRank = "6";
}
else
if (rank ==5){
strRank = "5";
}
else
if (rank ==4){
strRank = "4";
}
else
if (rank ==3){
strRank = "3";
}
else
if (rank ==2){
strRank = "2";
}
else
if (rank ==1){
strRank = "1";
}

if (suit==4){
strSuit= "Spades";
}
else
if (suit==3){
strSuit= "Hearts";
}
else
if (suit==2){
strSuit= "Diamonds";
}
else
if (suit==1){
strSuit= "Club";
}
else

return strRank + "of" + strSuit;

and i get the same missing return statement error here }
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: missing return statement

 
0
  #2
Mar 29th, 2006
first, you have a lot of if/else statemets that go on for more then 1 line so you need brackets. I ususual bracket no matter what just to be on the safe side. Another thing with the return statements, if you return something inside if statements it could be possible that it never tests it, so you need one at the end of the method definition. The last else statement doesn't seem like it is doing anything so you could remove it.
Well i think that's all the problems, post if you have any more questions or problems with it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 2
Reputation: gagirl14 is an unknown quantity at this point 
Solved Threads: 0
gagirl14 gagirl14 is offline Offline
Newbie Poster

Re: missing return statement

 
0
  #3
Mar 29th, 2006
thanks for the help. I didn't notice that extra else statement. It's working now :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: missing return statement

 
0
  #4
Mar 29th, 2006
nice
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 2
Reputation: malaya_champ is an unknown quantity at this point 
Solved Threads: 0
malaya_champ malaya_champ is offline Offline
Newbie Poster

Re: missing return statement

 
0
  #5
Apr 1st, 2006
public class Card
{

private int rank;
private int suit;

public Card()
{
suit = (int)Math.floor(Math.random() * (4-1) + 0.5) +4;
rank = (int)Math.floor(Math.random() * (14-2) + 0.5) +14;
}
public Card(int r, int s)
{
if (r>=2 && r<=14)
rank = r;
else rank = 14;

if (s>=1 && s<=4)
suit = s;
else suit = 4;
}
public int getSuit() //returns suit
{
return suit;
}
public int getRank() //return rank
{
return rank;
}

public boolean isHigher(Card c)
{
if (c.getRank() >rank)
{ //if Card is higher in rank return true
return true;
}
else
if (c.getRank() < rank)
{ //if Card is lower in rank return false
return false;
}
else
if (c.getRank() ==rank)
{ //if rank is equal then evaluate suit

if (c.getSuit() >suit)
{
return true;
}
else
if (c.getSuit() <suit)
{
return false;
}
}
return true;

//I get error here
}
public String toString()
{
String strRank = "";
String strSuit = "";

if (rank ==14){
strRank = "A";
}

else
if (rank ==13){
strRank = "K";
}
else
if (rank ==12){
strRank = "Q";
}
else
if (rank ==11){
strRank = "J";
}
else
if (rank ==10){
strRank = "10";
}
else
if (rank ==9){
strRank = "9";
}
else
if (rank ==8){
strRank = "8";
}
else
if (rank ==7){
strRank = "7";
}
else
if (rank ==6){
strRank = "6";
}
else
if (rank ==5){
strRank = "5";
}
else
if (rank ==4){
strRank = "4";
}
else
if (rank ==3){
strRank = "3";
}
else
if (rank ==2){
strRank = "2";
}
else
if (rank ==1){
strRank = "1";
}

if (suit==4){
strSuit= "Spades";
}
else
if (suit==3){
strSuit= "Hearts";
}
else
if (suit==2)
{
strSuit= "Diamonds";
}
else
if (suit==1){
strSuit= "Club";
}
else

return strRank + "of" + strSuit;
return strSuit;
// i get the same missing return statement error here }
}
public static void main(String mpo[])
{
System.out.println("rroop");

}
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC