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

import java.util.Scanner; public class Deck_Akash_Patel { public static void mai

ID: 3617267 • Letter: I

Question

import java.util.Scanner;

public class Deck_Akash_Patel
{

    public static void main(String args[])
   {
       Scanner kb = newScanner(System.in);
       int value;
       int suit;
       char s = 0;
       String card;



       System.out.println("EnterNumber: ");
       value = kb.nextInt();

       System.out.println("Enter SuitLetter: ");
       suit = kb.nextInt();

      
          if(suit==0)
           {
           s ='c';
           }
       else if(suit==1)
           {
              s='d';
           }
       else if(suit==2)
           {
              s='h';
           }
       else if(suit==3)
           {
              s='s';
           }
       else
       {
          System.out.println("Error");
       }

        if (value < 0 ||value >=13)
    {
        System.out.println("Error");
               System.exit(0);

    }

       
        card = toString();


       System.out.println(card);





    }



    public String toString(int value, int suit)
    {
       String cardvalue = "";
        String cardsuit ="";

        if (value ==1)
        {
           cardvalue ="Ace";
        }
        else if (value ==11)
        {
           cardvalue = "Jack";
        }
        else if (value ==12)
        {
           cardvalue = "Queen";
        }
        else if (value ==13)
        {
           cardvalue = "King";
        }
        else
        {
           cardvalue = Integer.toString(value);
        }

        if(suit == 0)
        {
        cardsuit = "clubs";
        }
        else if (suit == 1)
        {
        cardsuit ="diamonds";
        }
        else if (suit == 3)
        {
        cardsuit = "hearts";
        }
        else if (suit == 3)
        {
           cardsuit = "spades";
        }
        else
        {
           cardsuit = Integer.toString(suit);
        }
        return"the"+cardvalue+"of"+cardsuit;
        }



}



I AM TRYING TO MAKE THE TOSTRING FUNCTION TO WORK IN MY MAIN CLASS.I CANT GET IT TO RETURN TO THE MAIN FUNCTION. I HAVE TRIED ALOT OFDIFFERENT TYPES BUT NO LUCK.


THANKS FOR HELPING





Explanation / Answer

x.j5lor="red">please rate - thanks you left out the parameters in your call this answers your question, but --why enter numbers, in the main, change to letter, ignore the letter and change to string. see my suggested code after the fix import java.util.*; public class Deck_Akash_Patel {     public static void main(String args[])    {        Scanner kb = new Scanner(System.in);        int value;        int suit;        int s = 0;        String card;        System.out.println("Enter Number: ");        value = kb.nextInt();        System.out.println("Enter Suit (0=clubs, 1=diamonds,2=hearts,3=spades ");        suit = kb.nextInt();                 if(suit==0)            {            s = 'c';            }        else if(suit==1)            {                s='d';            }        else if(suit==2)            {                s='h';            }        else if(suit==3)            {                s='s';            }        else        {            System.out.println("Error");        }         if (value 13)     {         System.out.println("Error ");                 System.exit(0);     }               card = toString(value,suit);        System.out.println(card);     }    public static String toString(int value, int suit)     {        String cardvalue = "";         String cardsuit = "";         if (value ==1)         {             cardvalue ="Ace";         }         else if (value == 11)         {             cardvalue = "Jack";         }         else if (value ==12)         {             cardvalue = "Queen";         }         else if (value == 13)         {             cardvalue = "King";         }         else         {             cardvalue = Integer.toString(value);         }         if(suit == 0)         {         cardsuit = "clubs";         }         else if (suit == 1)         {         cardsuit = "diamonds";         }         else if (suit == 2)         {         cardsuit = "hearts";         }         else if (suit == 3)         {             cardsuit = "spades";         }         else         {             cardsuit = Integer.toString(suit);         }         return "the "+cardvalue+ " of "+cardsuit;         } } --------------------------------------- java.util.*; public class untitled {     public static void main(String args[])    {        Scanner kb = new Scanner(System.in);        int value;        char suit;            String card;        System.out.println("Enter Number: ");        value = kb.nextInt();         if (value 13)               {                 System.out.println("Error-invalid card entered ");                 System.exit(0);                } //check for error before you go on, no need to answer end question if 1st answer is bad        System.out.println("Enter Suit (c,d,h,s)");        suit = kb.next().charAt(0);                 if(suit!='c'&&suit!='s'&&suit!='h'&suit!='d')                   { System.out.println("Error-invalid suite entered");