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 7552531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:46:49+00:00 2026-05-30T10:46:49+00:00

I have 2 class files. One has the get/set statements and I need to

  • 0

I have 2 class files. One has the get/set statements and I need to write the code to use these get/set statements on another class file in the same project.
How can I do that?

Also, I want 2 random numbers as an output but I get only 1.

Card class:

public class Card{

//variables
public  int spades = 0;
public  int hearts = 1;
public  int diamonds = 2;
public  int clubs = 3;

public  int ace = 1;
public  int jack = 11;
public  int queen = 12;
public  int king = 13;

 private String rank;
 private String suit;


 //set methods
public void setSpades(String s){
    spades = 0;
}
public void setHearts(int h){
    hearts = 1;
}
public void setDiamonds(int d){
    diamonds = 2;
}
public void setClubs(int c){
    clubs = 3;
}

//get methods
public int getSpades(){
    return spades;
}
public int getHearts(){
    return hearts;
}
public int getDiamonds(){
    return diamonds;
}
public int getClubs(){
    return clubs;
}



public String getSuit() {
    return suit;
}
public void setSuit(String suit) {
    this.suit = suit;
}
public String getRank() {
    return rank;
}
public void setRank(String rank) {
    this.rank = rank;
}
}//end class

The second file:

public class PickTwoCards {

public static void main(String[] args){

     Card Object = new Card();
     Card Object2 = new Card();




     int ranSuit = (int)(Math.random()*10);
     System.out.println(ranSuit);       
}

public void Card (int theValue, int theSuit, int suit, int value){
    value = theValue;
    suit= theSuit;

}




}//End class PickTwocCards
  • 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-05-30T10:46:50+00:00Added an answer on May 30, 2026 at 10:46 am

    Let’s say that you have the following setter and getter methods in your first class:

    public void setName(String name) {
       this.name = name;
    }
    
    public String getName() {
       return name;
    }
    

    from the other class, you would call setName with yourObject.getName() once you’ve instantiated.

    Keep in mind, however, that beyond basic functions, getters and setters are considered bad:

    Are getters and setters poor design? Contradictory advice seen

    Allen Holub wrote "You should never use get/set functions", is he correct?

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

Sidebar

Related Questions

I have three files: one called sql.php witch has a class db that I
I used to have one class for one file. For example car.cs has the
I have a class split across two files. One of these is generated, the
i have a really basic java program just one .java/.class file (.java uncompiled .class
If I have the core of a class defined in one file as public
In one class I have a library project with a file class1 with namespace
I have a WAR file deployed to Tomcat server, one of the class will
I have created one user control for multiple file upload , i need to
I have a Java program that loads thirdparty class files (classes I did not
I have a database that I would like class files generated from, and also

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.