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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:42+00:00 2026-05-27T06:19:42+00:00

I have following problem to be solved in java: Implement class Alkio. Test with

  • 0

I have following problem to be solved in java: Implement class Alkio. Test with a done main programme AlkioPaa.java with which you see that your class functions.
My answer to this question is following:

/**
* @author A.
* @version 28.11.2011
* Tehtävä5. Ohjelma Toteuttaa luokan Alkio  */

public class Alkio {
  private int rivi;
  private int sarake;
  private int arvo;


   public Alkio(int rivi, int sarake, int arvo){
    int Rivi= rivi;
    int Sarake=sarake;
    int Arvo=arvo;
  }

  public void setAlkio(int rivi, int sarake, int arvo){
    System.out.println("("+rivi+","+sarake+","+arvo+")");
  }

  public int getArvo(){
    return arvo;
  }

  public int getRivi(){
    return rivi;
  }

  public int getSarake(){
    return sarake;
  }

  //jotain häikkää seuraavassa( 28.11.2011). Häikkä poistunut(29.11.2011)
  public String toString(){
    String merkkijono= new String();
    return merkkijono;
  }
}

Are there any comments?
Then Test is done with main programme AlkioPaa.java which is following:

public class AlkioPaa {

  public static void main(String[] args) {

    Alkio eka = new Alkio(1,2,10);

    System.out.println("Tein alkion, jonka rivi on " + eka.getRivi() 
       + " ja sarake on " + eka.getSarake() + ". Arvo on " + eka.getArvo());


    System.out.println("\n alkio on " + eka.toString());

    String apu = eka.toString();

    System.out.println("alkio " + apu);

    eka.setAlkio(2, 5, 12);

    System.out.println("Muutettu alkio " + eka);
  }
}

When I run main-program it prints:

Tein alkion, jonka rivi on 0 ja sarake on 0. Arvo on 0

alkio on
alkio
(2,5,12)
Muutettu alkio
So it does not print (1,2,10) as should be.

  • 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-27T06:19:43+00:00Added an answer on May 27, 2026 at 6:19 am

    Why do you expect it to print (1,2,10)?

    1. You re-set the values to 2,5, 12 (eka.setAlkio(2, 5, 12);). (although, as commented to the question by @flesk, you don’t actually set them…)
    2. you didn’t override the toString method as you should have:

      public String toString(){
          return "("+rivi+","+sarake+","+arvo+")";
      }
      
    3. In your constructor, you don’t set the class members to the given parameters, because you hide them in the method, the constructor should be:

      public Alkio(int rivi, int sarake, int arvo){
          this.rivi= rivi;
          this.sarake=sarake;
          this.arvo=arvo;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem using template instantiation [*]. file foo.h class Foo {
I have the following problem in my Data Structures and Problem Solving using Java
I have the following problem. If I query values with a keyfigure which is
I have to solve the following constructor for a BinaryTree class in java: BinaryTree(GeneralTree<T>
I have following class in Java code: public class CHRTreeCreator extends IndexCreator { ...
I was wondering how to implement the following problem: Say I have a 'set'
I'm writing a Java webservice with CXF. I have the following problem: A client
I have the following sample piece of code, public class test implements Runnable{ public
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
I have the following code which gets call in my main activity's onCreate method

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.