Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert this from Java to Ruby. //Define the method checkSet(). public static bo

ID: 3748114 • Letter: C

Question

Convert this from Java to Ruby.

//Define the method checkSet().

public static boolean checkSet (Card card one, Card card_two, Card card three)

//Initialize the required variables.

boolean rank status = false;

boolean color status = false;

boolean shape status = false;

boolean fill status = false;

//If rank of each card is same, then set the //rank status true.

if (card_one.rank_Of Card == card two. rank_of_Card && card one.rank_Of_Card == card_three.rank of_Card)

rank status = true;

//If rank of each card is different, then set // the rank status true.

else if (card one.rank Of Card != card two. rank_Of_Card && card_two.rank_Of_Card != card_three.rank_Of Card && card one. rank_Of_Card != card three.rank_of_Card)

rank status = true;

//If fill of each card is same, then set //the fill status true.

if (card_one.fill_card == card two.fill_card && card one.fill card == card three. fill card)

fill status = true;

//If fill of each card is different, then set

// the fill status true.

else if (card one.fill card != card two. fill card && card two.fill card != card_three.fill_card && card one.fill_card != card three.fill card)

fill status = true;

//If shape of each card is same, then set

//the shape status true.

if (card one.card shape == card two. card_shape && card_one.card_shape == card_three.card shape)

shape_status = true;

//If shape of each card is different, then set

//the shape status true.

else if (card_one.card shape != card_two. card_shape && card two.card shape != card_three.card_shape && card one.card_shape != card three.card shape)

shape status = true;

//If color of each card is same, then set

// the color status true.

if (card_one.card_color == card_two. card_color && card one.card color == card_three.card color)

color status = true;

//If color of each card is different, then set

//the color status true.

else if (card one. card color != card two. card color && card two.card color != card three.card color && card one. card color != card three.card color)

color_status = true;

//Get the result of AND of each status.

boolean isCardSet = rank status && color status && fill status && shape status;

//Return the result.

return isCardSet;

}

}

Explanation / Answer

// We are writing the code for the ruby

def checkSet (card_one, card_two, card_three)

rank_status= false

color_status = false

shape_status = false

fill_status = false

if card_one.rank_Of Card == card_two. rank_of_Card && card_one.rank_Of_Card == card_three.rank of_Card

puts rank_status = true

elsif card_one.rank Of Card != card_two. rank_Of_Card && card_two.rank_Of_Card != card_three.rank_Of Card && card one. rank_Of_Card != card three.rank_of_Card

puts rank_status = true

end

if card_one.fill_card == card_wo.fill_card && card_one.fill card == card_three. fill card

puts fill_status = true

elsif card_one.fill card != card two. fill card && card_two.fill card != card_three.fill_card && card one.fill_card != card_three.fill card

puts fill_status = true

end

if card_one.card_shape == card_two. card_shape && card_one.card_shape == card_three.card shape

puts shape_status = true

elsif card_one.card_shape != card_two. card_shape && card_two.card_shape != card_three.card_shape && card_one.card_shape != card_three.card_shape

puts shape_status = true

end

if card_one.card_color == card_two. card_color && card_one.card_color == card_three.card_color

put color_status = true

elsif card_one. card color != card_two. card color && card_two.card color != card_three.card_color && card_one. card_color != card_three.card_color

puts color_status = true

end

isCardSet = rank_status && color_status && fill_status && shape_status

puts "isCardSet"

end