Stuck on a program to print a number of a RANDOM card out of 52 cards

Bascically im going through a book called java elemenst and there is a lab little excerise based on the program underneath;
The prorgram picks a random card out of a deck(52 cards) and simply returns the card number.
The excercise is that with little moderation i change the program to print the cards value (1..13), followed by the number of suit (clubs are 1, spades are 4)
Ive tried but i make it too hard and too complicated when this for a begginer whilst i make it out as thought im much more!!i tried a if statement after making a variable spade and hearts but i then make casting problems.
Please can someone help me with such a easy program,and give me the code to make it work,i know the answer is probally in a few lines(cos its teh fisrt few pages of the book for begginers!!)
thank you anyway and heres the orginal working unchanged code ;
import java.util.Random;
public class Card
    public static void main(String args[])
        Random random = new java.util.Random();
        int drawn;
        // and add 1 to get a random integer 1..52
        drawn = java.lang.Math.abs(random.nextInt())%52+1;
          //i
        System.out.println("the card drawn is number " + drawn);
    }

The Java Tutorials are your friend(s). Use them. The following code is from here : [http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html|http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html]
import java.util.*;
public class Card {
    public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,
        SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }
    public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
    private final Rank rank;
    private final Suit suit;
    private Card(Rank rank, Suit suit) {
        this.rank = rank;
        this.suit = suit;
    public Rank rank() { return rank; }
    public Suit suit() { return suit; }
    public String toString() { return rank + " of " + suit; }
    private static final List<Card> protoDeck = new ArrayList<Card>();
    // Initialize prototype deck
    static {
        for (Suit suit : Suit.values())
            for (Rank rank : Rank.values())
                protoDeck.add(new Card(rank, suit));
    public static ArrayList<Card> newDeck() {
        return new ArrayList<Card>(protoDeck); // Return copy of prototype deck
}Then once you have the ArrayList of Cards use Collections.shuffle(list) to randomize the deck and then you can deal the cards

Similar Messages

  • Print tpage number/total page number in a report with width more than 240

    Dear all,
    I need to display total page number as following code sample.
    But I need to put it after position 240.
    this program can print total page number if   it is placed at postion 239 or before.
    WRITE: /234(10) 'Heading',  239 SY-PAGNO,'of ', '-----'.
    Whenever I put  240 or more WRITE: /234(10) 'Heading',  240 SY-PAGNO,'of ', '-----'.
    Total page num could not be displayed.
    Please tell me the solution.
    thanks
    REPORT YPAGECOUNT NO STANDARD PAGE HEADING LINE-SIZE 276  LINE-COUNT 65.
        DATA L_PAGE_COUNT(5) TYPE C.
    TOP-OF-PAGE.
      WRITE : /234(10) 'PAGE', SY-PAGNO,'/ ','-----', ''.
       WRITE: /234(10) 'Heading',  239 SY-PAGNO,'of ', '-----'.
        ULINE.
    START-OF-SELECTION.
      Real list output takes place here
        DO 1000 TIMES.
            WRITE: / 'Line #', SY-LINNO.
        ENDDO.
      Page count will be printed on each page here
        WRITE SY-PAGNO TO L_PAGE_COUNT LEFT-JUSTIFIED.
        DO SY-PAGNO TIMES.
            READ LINE 1 OF PAGE SY-INDEX.
            REPLACE '-----' WITH L_PAGE_COUNT INTO SY-LISEL.
            MODIFY CURRENT LINE.
        ENDDO.

    Using Values Greater than 255 for the LINE-SIZE of a List
    If you define a fixed column width greater than 255 using the LINE-SIZE addition in the REPORT or NEW-PAGEstatement, the following notes apply:
    Type definitions: The type group SLIST defines the valid maximum value for the list width (SLIST_MAX_LINESIZE), and contains a type for list lines with maximum width (SLIST_MAX_LISTLINE).
    Accessing the entire contents of a line: To read or modify the entire contents of a wide line, you can use the ... LINE VALUE addition in the READ LINE or MODIFY LINE statements. This is an alternative to using SY-LISEL that is independent of the attributes of the system field (since the length of SY-LISEL is 255 characters).
    Horizontal lines: With extra-wide lists, the "ULINE." statement corresponds to "WRITE / SY-ULINE.". So, for example, "ULINE AT 5(300)." corresponds to "WRITE AT 5(300) SY-ULINE.".
    Output length: You can use the length specification in WRITE (or ULINE) to extend the output length of an extra-wide list up to the value of LINE-SIZE. If you want to output a whole field that is longer than 255 characters, you must use this, even if the field itself is defined as longer than 255 characters.
    Example
    NEW-PAGE LINE-SIZE 1000.
    DATA: F1(500) VALUE 'F1'.
    WRITE: /      F1 COLOR COL_NORMAL.  " Output with length 255
    WRITE: /(500) F1 COLOR COL_NORMAL.  " Output with length 500
    Awrd Points if useful
    Bhupal

  • Print out all methods in program with print statements

    Does anyone know how I would be able to print out all the methods in a program. For example:
    class bd220p1 {
         public static void main(String args[])  {
              int lightspeedi,lightspeedm;
              long days;
              long seconds;
              long distancei;
              long distancem;
              // approximate speed of light in miles per second
              lightspeedi = 186000;
                // approximate speed of light in Kilometers per second
              lightspeedm = 300000;
              days = 1000; // specify number of days here
              seconds = days * 24 * 60 * 60; // convert to seconds
              distancem = lightspeedm * seconds; // compute distance in English system
              distancei = lightspeedi * seconds;// compute distance in Metric system
              System.out.print("In " + days);
              System.out.print(" days light will travel about ");
              System.out.println(distancei + " miles and");
              System.out.print(distancem + " Kilometers ");
    }This code would produce 5 print statements for the 4 methods:
    1 Main method
    2 Print method
    3 Print method
    4 Println method
    5 Print method
    Does anyone know I can write the could to accomplish this? Right now I am experimenting with try/catch statements. Any help is greatly appreciated.

    It seems to me the easiest approaches (other than using a tool someone else has already written) are:
    1) Compile the source, and then use BCEL
    2) Try some regular expressions; it won't be perfect but maybe you can tweak it until it's good enough.
    3) Parse the source, and examine the parse tree.
    1 and 3 will give you much better results, but require you to use outside libraries (or write a parser yourself).
    You can do 2 using standard stuff from the JDK, but you may spend a lot of trial-and-error gettng the regexps right.
    Which you choose will depend a lot on what the prof giving the assignment allows.
    Also he may have some particular kind of solution in mind -- did he say anything?
    If you're not sure what to do, ask your prof for clarification.

  • Standard program to print Customer Invoice with G/L lines

    Hello All,
    Requirement is as follows : -
    1) We are trying to print the FI customer invoice through correspondence (Transaction Code F.61)
    Standard driver program RFKORD50 and SAPscript F140_DOCU_EXC_01 are provided for the invoice printing.
    2) Standard driver program currently prints either the customer line items / the vendor line items in the invoice.
    3) Requirement is that we need to print the G/L line items on the form, instead of customer or vendor line item.
    4) Client wants to go ahead with standard program only and is not ready for custom driver program or enhancments in the system.
    5) So is there any standard driver program and script which prints the G/L line items in the customer invoice.
    Thanks in advance.
    Regards,
    Rinkesh Doshi

    Hi,
    I don't know standard script for G/L line items,but your client requirement is not to change the standard one.My suggestion is to create a standard text.By Using subroutine pool ,save  the  line items data(internal table ) into standard text after that include the standard text into your sap script form.
    just go through this <link to blocked site removed by moderator>
    Thanks and regards
    Naresh Bammidi
    Edited by: Thomas Zloch on Dec 15, 2011 9:16 PM

  • Use abap report program to print bar code instead of smartforms

    Do anyone know how to use abap report program to print bar code?

    Hi Celina,
    http://searchsap.techtarget.com/tip/1,289483,sid21_gci839063,00.html
    I hope this will help, also it depends on the barcode type like ARTNR-code 128...
    Regards,
    Sudhi

  • In Contacts version 8, how can I print ALL information in each individual card? When I select the print command the only thing printed is the name and address. I need phone number(s) and all other information in the cards.

    In Contacts version 8, how can I print ALL information in each individual card? When I select the print command the only thing printed is the name and address. I need phone number(s) and all other information in the cards. We enter various pieces of data, other than the standard name address & phone numbers and we print all information on each card so it fits in a 5x7 inch loose binder. We have used InTouch software for many years and it has served us extremely welll, however, the publisher (The Prairie Group) has not, and apparently has no plans to update their software to be compatible with any Mac OSX OS beyond 10.6. Any help will be appreciated!

    You can select what you want included in a list format. In the Print command from Contacts, click the Show Details button. Then in the Style pulldown menu select "Lists" and there you'll be able to select what you want included. You can also select what you wish included if you select the Pocket Address Book style.
    If neither of those options will work for you, then you will need to look to third-party software. Here's one possibility that seems to get good reviews:
    https://www.macupdate.com/app/mac/15485/labels-&-addresses
    I haven't done more than try it to make sure that it works with OS X 10.9's Contacts, which it does, but you can download their demo and try it yourself.
    Regards.

  • How can I print the "number lines" with the code in Visual Studio?

    How can I print the "number lines" with the code in Visual Studio?

    Hi BillionaireMan,
    What about your issue now?
    If you have resolved it, you can share the solution here, which will be beneficial for other members with the same issue.
    If you did not, please tell us more information,we will try my best to help you.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Any table or program to get the number of records in P, A and F tables

    HI all
    any table for program to get the number of records in P, A and F tables. I want to create SQ01 queries to get the status of number of records. We are gng for a production cutover next week. Want to capture all the data before and after Upgrade cutover.
    Also suggest me how to create sq01 queries.
    Thanks in advance
    regards
    Janardhan KUmar K.

    Use Transaction LISTSCHEMA to see all the tables assosciated with ur cube
    Total number would be what you find in both the E & F fact tables. If there is no compression in the cube then E table will be empty.
    Alternatively u can use se16 transaction and enter E table and F table manually
    E table - /BIC/E(Cube name) and Ftable -  /BIC/F(Cube name)
    Or else u can go to the manage of the cube and without selecting any field for O/P and ticking the option output number of hits execute. The total of Row Count will give u the total no of records in the cube.

  • Looking for a for an all-in-one printer that is compatible with greeting card programs..​.

    looking for a for an all-in-one printer that is compatible with greeting card programs...my original one was an HP PSC  1510...replaced it with a Deskjet 1050 & it does not work...any suggestions?

    I bought an epson xp650 a couple of months ago and cannot fault it. It does everything I require and it is the wifi model so I can print directly from my ipad/iphone. Not sure if you are asking about the colour of the unit or just to be able to print black and white, Obviously all printers will print black and white but just to give you a little more info the printer I bought is the white version and it looks really nice sat next to my imac 27''
    Hope this helps.

  • I can no longer directly print from the USPS print servelet. I now have to save the file and rename the extension to PDF load in another program to print. It used to be automatic. What happened?

    When trying to print from the USPS website (to print a label) when I click to pay and print instead of my print selection screen coming up I get the "Firefox doesn't know what to do with this" screen. THrough some web searching I found I can save the file, then change the extension to PDF and load it in another program and print but it adds two steps and is a real pain. Why would this have changed????

    It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox.<br />
    Try to disable the real-time (live) scanning of files in your anti-virus software temporarily to see if that makes downloading work.
    See also "Disable virus scanning in Firefox preferences - Windows"
    * http://kb.mozillazine.org/Unable_to_save_or_download_files

  • Printing fixed number of  Invoice Line in rtf template with level two group

    Hi,
    I have to print fixed number of invoice lines on a page. Invoce tempalte design has a table with header and summary(Invoice , tax and shiping totals) at each page in table footer. The table should repeate at each page with header and footer. I need to print specific number of rows or number of rows wihich page can accumulate in table body on each page.
    I checked few blogs giving solution for fixed number of rows printing say
    "Anatomy of a Template I - Fixed Row Enumeration"(http://blogs.oracle.com/xmlpublisher/2007/03/27/)
    and
    http://oracle.anilpassi.com/xml-publisher-developing-reports-printed-on-pre-printed-stationary-2.html
    Above two blogs explanation has only one group at line level. but in my case there are two groups (Parent and child) at line level. I am able to count rows in parent group but it is not counting lines in child group.
    Edited by: Bhanu Yadav on Apr 19, 2011 2:10 AM

    Will it be possible for you to move the 1st and 3rd sections to header/footer?
    So that if the 2nd section spills over to next page too, starting position of 3rd section wont be affected.

  • XSL-FO for Standard Purchase Order, doesn't print page number

    Hi,
    I worked on XSL-FO code to custom the PDF output for Standard PO. Everything works great: I added company logo (in a different position of the standard commented code <!-- Too easy just to uncomment... :-)--> ), i created new attribute sets to highlight some elements on the print, I added a footer with company details and document type and number (instead of placing this in the header, the costumer didn't like it where it was..)
    OK. BUT: the page number at the bottom on the right isn't printed anymore. For example: if the PO page is n.1 of 2 pages, it comes only '12' and not Page 1 of 2. So i tought not to use the original template (tihs one)
    <!-- Template for displaying the page numbers -->
    <!-- bug#3836856: Template for displaying the page numbers at right bottom of the page -->
    <xsl:template name="pageNumber">
         <xsl:variable name="po_page">
         <xsl:value-of select="$BOILER_PLATE_MESSAGES_OBJ[MESSAGE='PO_FO_PAGE'][1]/TEXT"/>
         </xsl:variable>
         <!-- Get the String before the PAGE_NUM token -->
         <xsl:variable name="string_before_page_num">
         <!-- <xsl:value-of select="substring-before($po_page,'&amp;PAGE_NUM')"/>-->
         <xsl:value-of select="substring-before($po_page,'Pag.;PAGE_NUM')"/>
         </xsl:variable>
         <!-- Get the String after the PAGE_NUM token -->
         <xsl:variable name="string_after_page_num">
         <!-- <xsl:value-of select="substring-after($po_page,'&amp;PAGE_NUM')"/>-->
         <xsl:value-of select="substring-after($po_page,'/ ;PAGE_NUM')"/>
         </xsl:variable> ......
    but inseriting a select just where I want the page num to be displayed (see code)
    <fo:block xsl:use-attribute-sets="test_style" >
    <xsl:value-of select="$BOILER_PLATE_MESSAGES_OBJ[MESSAGE='PO_FO_PAGE'][1]/TEXT"/>
                                                      </fo:block>
    but this gave me as result 'Page &PAGE_NUM of &END_PAGE'.
    Where did I do wrong?? It's like the PO_FO_PAGE message is not dinamically insered in the PDF. Hope I've been clear enough and somene can help me. Thaks in advance, Michele

    Hi Michele:
    I can check out for you how to print page number in XSL-FO (There is an O'Reilly) book, but I think I help you better by recommending a different strategy - Don't write XSL-FO stylesheets. While Purchasing does not support RTF templates you can still write RTF templates and convert them to FO using the XML Publisher Template Builder for Word.
    Download the matching Template Builder for Word (5.0) or XML Publisher Desktop 5.5 (includes the Template Builder) patch and then Create your template as an RTF template.
    You can then EXPORT the template as XSL-FO stylesheet and upload as to Purchasing AS LONG AS THE VERSION OF THE DESKTOP and E-Businees Suite XML Publisher MATCH.
    If you still want to write XSL stylesheet, you can just use the Template Builder to generate you the code and paste the code (e.g. for page numbers) into your stylesheet.
    By the way - Purchasing will support RTF templates in future versions...
    Hope that helps,
    Klaus

  • My InDesign program is printing my placed images lighter than illustrator.

    I am trying to print a colour logo in Indesign with black type on my inkjet printer.  The colours are appearing fine on screen and so is the black but when I print everything is washed out.  I tried just printing a black box and it appears black on screen but in print it is grey.  I have tried changing the preferences Appearance of Black to rich and accurate but that did not make a difference.  Do I need to do anything in color management I am using Indesign CS2.  How can I solve this problem?

    Acrobat worked, thanks for that advice.   I set my Convert to Profile under the Edit Menu to  Color
    Match RGB.  That helped a little bit but it is not printing like the
    pdf.  I would like to get this problem resolved. I normally use
    illustrator most of my work.  But I would like to have InDesign working
    properly as I need it to do other jobs.
    Take Care,
    Jen
    Take Care,
    Jen
    Date: Fri, 14 Aug 2009 14:24:47 -0600
    From: [email protected]
    To: [email protected]
    Subject: My InDesign program is printing my placed images lighter than illustrator.
    Jen,
    This is a problem that you have no time to fool with, correct?
    When printing from InDesign and all looks hopeless, export to PDF and print from the PDF.
    Why?
    I don't know for sure but it seems all printers made recently accept PDF better than straight from InDesign. It could be the printer driver and it could be InDesign but you don't have time to mess with it now. Wait for some free time to sort it out, but for now output to PDF and print from Adobe Reader or Acrobat.
    >

  • Program at print button in 'Issue output to'

    Hello Experts,
    There is an existing output X which triggers only when output BA00 is printed from the print button in the pop up of sales order when you go to 'Isssue output to'
    When trying to process the sales order output BA00 throu standard program SD70AV1A, the output X is not triggered.
    Now, we have a requirement to process BA00 from another interface where we are using SD70AV1A, but output X is not triggering in this case.
    So, please suggest a way through which we can use the program at print button in this requirement.
    Thanks in advance.
    Paritosh

    Hello Max,
    Thanks for your reply
    BA00 is printed by program, no issues there. But, there is a requirement on other output X(medium 5) , that it should process immediately along with BA00, which is not happening with this program SD70AV1A.
    Paritosh

  • Cannot open PDF after I created it in my program under PRINT

    cannot open PDF after I created it in my program under PRINT
    Tried uninstalling and re-installing
    I have Reader X to open it with but all that comes through is this message-
    ERROR: undefined
    OFFENDING COMMAND: VM?
    STACK:
    105000

    Thank you for your response...
    I am creating a file in Adobe PageMaker and wanting to make it a PDF for others to view who may not have that program.
    I am operat ing under Windows 7 if that helps any.
    The content of what I am sending shouldn't matter- just JPG's and text.
    Should I uninstall my PDF reader and Cute PDF and re-load them back in?
    Sincerely,
    Leanne

Maybe you are looking for

  • Stuck at 21% of the Dreamweaver CS 5.5 installer

    My situation before i had troubles: - CS3 Web Premium installed; - Dreamweaver CS5.5 upgrade installed over this; - I tried installing the latest mobile development update for DW CS5.5 but kept getting the U44M1P7 error so i followed this guide: http

  • How do I get my old iphone to sync with my new Macbook Pro?

    I just bought a new Macbook Pro and was able to get all my files and such from my old computer, which was a Macbook about 4 years old. But the problem now is that when I plug in my iphone to the new computer it will not recognize the phone in my itun

  • Sequence an App-v 5.0 application that uses a vbscript in which is pointed to c:\program files (x86)

    Hi, I have this application I need to sequence. It has an hta which points to exe which start with configfiles  in c:\program files (x86)\myapplication Sequencing works fine but when I open the package on another machine it says "path c:\program file

  • Flash Animation Work Very Slowly

      Flash animation work slowly in any brousers (Mozila,IE,Opera, ect), but work properly in standelone Flash Player. Any version of plagins can't solve this problem, using/disabling hardware acceleration have no efect. Using Windows XP SP3, intel-core

  • I lost my address book on my computer

    I am going on bed rest and willl be working from home... welll just now I some how lost my address book... I don't know how it happend but its gone... can I retrieve it... please help!!