Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:47:11+00:00 2026-06-10T22:47:11+00:00

I am writing an applet that will randomly pick 10 cards and show them

  • 0

I am writing an applet that will randomly pick 10 cards and show them on the screen. However, I am receiving a .class error and a ; needed error when I attempt to pass an String[]. Anyone help? This is my code:

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.applet.Applet;
import java.lang.Math;
import java.util.Random;

public class unit12Assignment extends Applet
{
Image card1 ... card52;

public void init()
{
    card1 = getImage( getDocumentBase(), "c1.gif" );
    ...
    card52 = getImage( getDocumentBase(), "sk.gif" );
}

public void getCards()
{
    String cardNumber; 
    double cardRandom;
    int cardRandomNumber;
    String[] cardSelection = new String[10];
    Random ran = new Random();

    for (int number = 0; number <=  9; )
    {
        cardRandom = ran.nextInt(52) + 1;
        cardRandomNumber = (int) Math.round( cardRandom );

        if ( cardRandomNumber > 0 && cardRandomNumber <= 52 )
        { 
            cardNumber =  "card" + cardRandomNumber;
            number++;
        }
    }   
    paint( String[] cardSelection );
}

public void paint(Graphics g, String[] card)
{
    setBackground( Color.green );
    g.drawImage( card[0], 10, 10, this);
    g.drawImage( card[1], 90, 10, this);
    g.drawImage( card[2], 170, 10, this);
    g.drawImage( card[3], 250, 10, this);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:47:13+00:00Added an answer on June 10, 2026 at 10:47 pm

    This line:

    paint( String[] cardSelection );
    

    should syntactically be

    paint( cardSelection );
    

    You only need to write the type (for example String[]) before a variable when you first declare it. From there it can just be referred to by its name.

    I also notice that paint takes a Graphics argument as well as a String[], so you’ll need to pass that in as well:

    Graphics g = getGraphicsSomehow();
    paint(g, cardSelection);
    

    EDIT: see Andrew Thompson’s answer for a disclaimer on using Graphics with an alternative solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an applet that's supposed to show both English and Japanese (unicode) characters
I am writing an app that will use Reverse Geocoding to translate the user's
I'm writing a receipt printing tool that will print receipts to the Star TSP100
I'm writing a web application that allows users to upload documents importing them directly
I'm writing an iOS application that will play audio instructions as one of it's
I am writing a program that will allow me to open excel spreadsheets and
I'm writing an app that will allow iPhone users to login to their accounts.
I have a Java applet that uses the HTTPURLConnection class to upload very large
I am writing a universal app that will be used primarily at night. I
I'm writing an applet, which uses ~10 external libraries. Together they occupy more than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.