Results 1 to 16 of 16

Thread: need help

  1. #1
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default need help

    import java.io.*;

    class tugas1{
    int i,j,k;
    public void tugas1 (int bil){
    for(i=1;i<=bil;i++)
    {
    System.out.print("nama peserta ke-"+i+" = ");
    na[i] = nama.readLine();
    }

    System.out.println("");
    }
    }

    class sasuke extends tugas1{
    public void tugas1 (int bil){
    int a=0,aa=0;
    for (i=1;i<=bil;i++){
    System.out.print("nilai untuk "+na[i]+" = ");
    nilai = Integer.parseInt(nama.readLine());


    if(nilai>aa)
    { a=i;
    aa=nilai;
    }
    }
    System.out.println("");
    System.out.println("Nilai tertinggi = "+na[a]);
    }
    }
    class polimorfime
    {
    public static void main (String[] args) throws Exception
    {
    DataInputStream nama=new DataInputStream(System.in);
    System.out.print("jumlah peserta : ");
    int bil = Integer.parseInt(nama.readLine());
    String[] na = new String[bil+1];
    System.out.println("");

    tugas1 p;

    tugas1 atas=new tugas1();
    p=atas;
    p.tugas1(int bil;String[] na);
    sasuke bawah=new sasuke();
    p=bawah;
    p.tugas1(int bil;String[] na);

    }
    }
    Last edited by decky; 06-14-2011 at 12:25 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Can you explain what you need help with?

    Why is this posted in the Threads section?

  3. #3
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    I was difficult to use inheritance and polymorphism
    Can you help me

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Can you explain what your problem is?

  5. #5
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    Can you try it?

    I'm confused, why can not compile the program?

    help me to repair

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Please copy and paste here the FULL text of the error messages you get.

  7. #7
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Please post the full text of any error messages you get, so we can explain what's wrong.

    Just looking at the code, you are using arrays and objects that haven't been declared or initialized (na[], nama, nilai). You seem to be trying to call a method, but the code is scrambled:
    Java Code:
    p.tugas1(
    int bil; 
    String[] na);
    Also, when posting code here, please use the CODE tags to keep it formatted and readable, and use the Java Naming Conventions - class names should start with an uppercase letter, method and variables names should start with a lowercase letter.
    Last edited by dlorde; 06-14-2011 at 01:58 PM.

  8. #8
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    test.txt

    this full text

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Please copy and paste the text of the error messages here. Not a file to download.

  10. #10
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    import java.io.*;

    class tugas1{
    int i,j,k,nilai;
    String nama;
    String [] na;
    public void tugas1 (int bil)throws Exception{
    DataInputStream nama=new DataInputStream(System.in);
    String [] na = new String[bil+1];
    System.out.println("");
    for(i=1;i<=bil;i++)
    {
    System.out.print("nama peserta ke-"+i+" = ");
    na[i] = nama.readLine();
    }

    System.out.println("");
    }
    }

    class sasuke extends tugas1{
    public void tugas1 (int bil,String [] na){
    int a=0,aa=0;
    for (i=1;i<=bil;i++){
    System.out.print("nilai untuk "+na[i]+" = ");
    nilai = Integer.parseInt(na [i]);


    if(nilai>aa)
    { a=i;
    aa=nilai;
    }
    }
    System.out.println("");
    System.out.println("Nilai tertinggi = "+na[a]);
    }
    }
    class polimorfime
    {
    public static void main (String[] args) throws Exception
    {
    DataInputStream nama=new DataInputStream(System.in);
    System.out.print("jumlah peserta : ");
    int bil = Integer.parseInt(nama.readLine());


    tugas1 p;

    tugas1 atas=new tugas1();
    p=atas;
    p.tugas1(bil);

    sasuke bawah=new sasuke();
    p=bawah;
    p.tugas1(bil);


    }
    }

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Please copy and paste the text of the error messages here.

  12. #12
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    after class tugas1 not get to class sasuke
    but returned to class tugas1

  13. #13
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    OK, that's an improvement - apart from the Java Naming Conventions...

    The only structural issue I can see is that you need one of those classes (preferably the class with the 'main' method) to be public, and it should be in a .java file with the same name as the class, e.g. public class Polimorfime { ... in a file called Polimorfime.java. The other classes can stay in there.

    I have no idea what it does - nothing useful, as far as I can see...

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default

    Does your program compile with no errors?
    Is your problem with the execution? Does it throw an exception?

    after class tugas1 not get to class sasuke
    but returned to class tugas1
    Add some println statements to the code to show where the execution goes and that shows where it is going that is wrong.
    Copy and paste that printed output here with an explanation of what is wrong with it.

    Have you tried using Google translator from your language to English? That may help you post messages that explain your problem better.

  15. #15
    decky is offline Member
    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    Default

    this's my home work
    i must use inheritance and polymorphism
    but i can't understand it

  16. #16
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by decky View Post
    this's my home work
    i must use inheritance and polymorphism
    but i can't understand it
    Well we can't help you unless you explain exactly what you have been asked to do, and why you've written the code you posted, and what you're having difficulty with.

    If you don't understand something about inheritance and polymorphism, explain what it is you don't understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •