Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Java Online

//Name: Erik sadoff

import static java.lang.System.*;

public class cardRunner
{
    public static void main(String args[])
    {
        
        Card one = new Card("Spades", 9);
        out.println(one.getSuit());
        out.println(one.getFace());
        
        Card two = new Card("Diamonds", 1);
        out.println(two);
        two.setFace(3);
        out.println(two);
        
        Card three = new Card("Clubs", 4);
        out.println(three);
        
        Card four = new Card ("Spades", 1);
        out.print (four);
        out.println (" 11");
        
        Card five = new Card ("Hearts", 13);
        out.print(five);
        out.println(" 10");
         
        Card six = new Card ("Hearts", 12);
        out.print(six);
        out.println(" 10");
    
        Card seven = new Card ("Hearts", 11);
        out.print (seven);
        out.println(" 10");
        
        Card eight = new Card ("Clubs", 12);
        out.print (eight);
        out.println (" 10");
        
    }
}
//
class Card
{
    public static final String FACES[]={"Zero", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};

    private String suit;
    private int face;
    //
    public Card (String s, int f)
    {
        suit = s;
        face = f;
    }
    public void setFace (int f)
    {
        face = f;
    }
    public void setSuit (String s)
    {
        suit = s;
    }
    //
    public String getSuit()
    {
        return suit;
    }
    public int getFace()
    {
        return face;
    }
    //
    public String toString()
    {
        return FACES[face] + " of " + suit;
    }
}
class BlackJackCard extends Card
{
    public BlackJackCard (String s, int f)
    {
        super (s, f);
    }
    public int getValue()
    {
        if(getFace() == 1)
        
            return 11;
        
        if(getFace() > 10)
        
            return 10;
        else
            return getFace();
    }
    public String toString()
    {
        return super.toString() + " " + getValue();
    
    }
    
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.