• Post Reply Bookmark Topic Watch Topic
  • New Topic

candidates  RSS feed

 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the programme below doesnt work. there are errors inside. can i get your help in correcting these errors. thanks




import javax.swing.*;

public class Candidates {

// data members

private int[] num;
private String[] name;
private double[] votes;

//methods

public Candidates(int numC, String nameC, double votesC){

num = new int[4];
name = new String[nameC];
votes = new double[votesC];
}
public void readNum(){

String numStr;
String nameStr;
String voteStr;
for(int i = 0; i< num.length; i ++);
String numStr = JOptionPane.ShowInputDialog("Enter the number of candidates");
int numC = Integer.parseInt(numStr);
String nameStr = JOptionPane.ShowInputDialog("Enter the name");
int nameC = nameStr;
String voteStr = JOptionPane.ShowInputDialog("Enter the number of votes");
double votesC = Double.parseDouble(voteStr);
}
}
public int TotPercent(){
double[] percent;

for(int i = 0; i < num.length; i++){
if(name[i] && votes[i]) {
percent[i] = votes[i] / votes[i]+ votes[i+1]+ votes[i+2]+ votes[i+3];
}
}
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that you are posting your questions in the wrong forum. We have a Swing forum, and this forum is for J2ME which is for Mobile Devices. I will move all your posts to the correct forums.

Mark
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looking at the errors - is this an assignment on debugging?

if not,
what is the program supposed to do?
where do the arguments supplied to the constructor come from?
 
kofi ofei
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i copied it from a site and typed it up in my editor. the arguments within the contructor were made up. the programme is suppose to allow the user to type in the name of the candidate, the number of votes etc in the JOptionPane dialogue box
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rather than trying to fix the above, here's a different way of doing it
see if you can follow how it works

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kofi ofei:
i copied it from a site and typed it up in my editor.


Ah. OK. Now it starts to become clear.

JavaRanch is for people who are trying to learn to program in Java. They come here, they ask questions about Java, the language. We answer their questions. People recommend books, websites, etc.

Programming is not something you pick up in an afternoon. It takes a lot of study and experience. There's no shortcut. You can't just take bits of code from here and there and somehow "stick them together" to make something more without understanding the language.

In quite a few of your threads, you've stated that on running a program, "nothing happens", whereas people have replied that in fact the program seems to work fine. This makes me think that you probably don't know how to run Java programs at all. You need to be able to walk before you can run.

If you're interested in learning, you need to back way up, and start with "How do I compile and run a Java program?" You've got to get a "Hello, World" program to compile and run before you get anywhere near the stuff you're looking at here.

If you're not interested, you might consider hiring a consultant to do some programming for you! We've got a dandy "Jobs Offered" forum right here at the Ranch.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!