Why am I not able to call the class Ballots from Assig4 Assig4.java import java.
ID: 3688722 • Letter: W
Question
Why am I not able to call the class Ballots from Assig4
Assig4.java
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Assig4{
public static void main(String []args){
System.out.println("Please enter the Ballots file you are using (.txt included).");
String ballotFile;
Scanner bal = new Scanner(System.in);
ballotFile = bal.nextLine();
Ballots bl = new Ballots();
bl.ballots(ballotFile);
}
}
Ballots.java
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Ballots{
public ballots(String ballotFile){
System.out.println("You have made small progress.");
}
}
Explanation / Answer
Hi, I have made small change in Ballots.java file. It working fine now. Changes highlighted in bold. you should specifiy th return type while defining any method. In our case, you have forgotten to mention return type as void.
Assig4.java
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Assig4{
public static void main(String []args){
System.out.println("Please enter the Ballots file you are using (.txt included).");
String ballotFile;
Scanner bal = new Scanner(System.in);
ballotFile = bal.nextLine();
Ballots bl = new Ballots();
bl.ballots(ballotFile);
}
}
Ballots.java
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Ballots{
public void ballots(String ballotFile){
System.out.println("You have made small progress.");
}
}
Output:
Please enter the Ballots file you are using (.txt included).
D:\test.txt
You have made small progress.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.