Results 1 to 16 of 16
Thread: need help
- 06-14-2011, 01:10 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
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 01:25 PM.
- 06-14-2011, 02:36 PM #2
Can you explain what you need help with?
Why is this posted in the Threads section?
- 06-14-2011, 02:38 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
I was difficult to use inheritance and polymorphism
Can you help me
- 06-14-2011, 02:40 PM #4
Can you explain what your problem is?
- 06-14-2011, 02:45 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
Can you try it?
I'm confused, why can not compile the program?
help me to repair
- 06-14-2011, 02:53 PM #6
Please copy and paste here the FULL text of the error messages you get.
- 06-14-2011, 02:55 PM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 13
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);
Last edited by dlorde; 06-14-2011 at 02:58 PM.
- 06-14-2011, 03:01 PM #8
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
test.txt
this full text
- 06-14-2011, 03:04 PM #9
Please copy and paste the text of the error messages here. Not a file to download.
- 06-14-2011, 03:05 PM #10
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
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);
}
}
- 06-14-2011, 03:06 PM #11
Please copy and paste the text of the error messages here.
- 06-14-2011, 03:10 PM #12
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
after class tugas1 not get to class sasuke
but returned to class tugas1
- 06-14-2011, 03:14 PM #13
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 13
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...
- 06-14-2011, 03:15 PM #14
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
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.
- 06-14-2011, 03:23 PM #15
Member
- Join Date
- Jun 2011
- Posts
- 7
- Rep Power
- 0
this's my home work
i must use inheritance and polymorphism
but i can't understand it
- 06-14-2011, 04:01 PM #16
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 13
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.
Bookmarks