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

  • SEARCH
  • Home
  • 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 9207955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:30:16+00:00 2026-06-18T00:30:16+00:00

I have problem with printing out the output . The class methods : public

  • 0

I have problem with printing out the output .

The class methods :

public class Account {
    private String name1;
    private String name2;
    private  double grade1;
    private  double grade2;
    private  double grade3;
    private  double average;
    public void setAccount(String a1 ,String a2 ,double b1,double b2,double b3) {

        a1=name1;
        a2=name2; 
        b1=grade1;
        b2=grade2;
        b3=grade3;
    }

    public void setaverage(double k1){
        k1=average;
    }

    public String getAccount(){
        return name1;
    }

    public String getAccount1(){
        return name2;
    }

    public double getAccount2(){
        return grade1;
    }

    public double getAccount3(){
        return grade2;
    }

    public double getAccount4(){
        return grade3;
    }

    public double getaverage(){
        return average=(grade1+grade2+grade3)/3;
    }
}

And the main method:

    public static void main(String[] args) {
        Scanner in = new Scanner (System.in);

        Account account= new Account();

        System.out.println("Enter the  frist  and last name of student" );

        String na1=in.nextLine();

        account.getAccount(na1);

    } // end main

} // end class AccountTest

I have problem in account.getAccount(na1);

I tried to print one String to know if the program works .

So how to print the output?

I know that the problem because there’s no argument in the get method, but I don’t know how to print it, since it’s my first time using it .

  • 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-18T00:30:18+00:00Added an answer on June 18, 2026 at 12:30 am

    There are plenty of issues here but don’t worry I’ll run you through them. There’s lots of little things you can do to make your code easier for you and others to understand. Encapsulation seems confusing at first but it starts to make sense pretty fast I found. First off in your constructor you’re doing the assignment backwards. I take it your teacher is making you use “getters” and “setters” for every private variable?

    Create methods with these signatures:

    public void setName1(string n1){...}//assigns n1 to name1
    
    public void setName2(String n2){...} //assigns n2 to name2
    
    public void setGrade1(double g1){...} //assigns g1 to grade1
    
    public void setGrade2(double g2){...} //assigns g2 to grade2
    
    public void setGrade3(double g3){...} //assigns gee I wonder.
    

    And use them in your constructor:

    public void setAccount(String n1 ,String n2 ,double g1,double g2,double g3) {
    
        setName1(n1);
        setName2(n2);
        setGrade1(g1);
        setGrade2(g2);
        setGrade3(g3);
    
    
    }
    

    Next I’d reccommend naming your get* methods in a similar way.

     public String getName1(){...}
     public String getName2(){...}
     public double getGrade1(){...} 
    

    etc.

    And, finally, for printing. Once you have all that set up printing to the console is very easy.

    System.out.println(getName1()); //will print name1 to the console.
    

    Read through the code and annotate it to explain (to yourself) what it’s doing. It starts to read more and more like english/humanLanguageOfChoice as you go on!

    I’m a student too so if any real developers feel like having a dig go ahead.

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

Sidebar

Related Questions

I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
i have problem with printing the array after reading it. After printing, the address
I am getting this strange output in HashMap . I have two ArrayList<String> one
So I've been working on this problem of printing out a Sudoku board for
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my
I have problem while loading data into html select when users press or click

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.