Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MyProgram.java:7: error: 'void' type not allowed here
question(System.out.println("Return true if the supplied character is 'a'"));
^
MyProgram.java:21: error: cannot find symbol
for (int i = 0; i < s.length() && aCounter <= 2; ++i) {
^
symbol: variable aCounter
location: class MyProgram
MyProgram.java:23: error: variable i is already defined in method hasTwoA(String)
for(int i = 0; i < s.length(); i++)
^
MyProgram.java:73: error: cannot find symbol
for(int i = 1; i < word.length; i++)
^
symbol: variable word
location: class MyProgram
MyProgram.java:75: error: cannot find symbol
if(word[i].length()>=four.length()){
^
symbol: variable word
location: class MyProgram
MyProgram.java:75: error: cannot find symbol
if(word[i].length()>=four.length()){
^
symbol: variable four

location: class MyProgram
MyProgram.java:97: error: cannot find symbol
switch (userInt){
^
symbol: variable userInt
location: class MyProgram
MyProgram.java:97: error: illegal start of type
switch (userInt){
^
MyProgram.java:122: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:126: error: cannot find symbol
days = 29;
^
symbol: variable days
location: class MyProgram
MyProgram.java:131: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:134: error: cannot find symbol
days = 30;
^
symbol: variable days
location: class MyProgram
MyProgram.java:137: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:140: error: cannot find symbol
days = 30;
^

symbol: variable days
location: class MyProgram
MyProgram.java:143: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:146: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:149: error: cannot find symbol
days = 30;
^
symbol: variable days
location: class MyProgram
MyProgram.java:152: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
MyProgram.java:155: error: cannot find symbol
days = 30;
^
symbol: variable days
location: class MyProgram
MyProgram.java:158: error: cannot find symbol
days = 31;
^
symbol: variable days
location: class MyProgram
20 errors

What I have tried:

import java.util.*;
public class MyProgram
{
public static void main(String[]args)
{
System.out.println("Problem 1 = " + isLetterA('a'));
question();
System.out.println(daysInMonth(2,1970));
}//end main

//problem1
public static boolean isLetterA(char letter)
{
return letter == 'a';
}//endproblem1

//problem2
public static boolean hasTwoA(String s)
{
boolean q = false;
for (int i = 0; i < s.length() && aCounter <= 2; ++i) {
int count = 0;
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == 'a')
count++;
}
if(count >= 2)
return true;
return q;
}}//endproblem2

//problem3
public static boolean isVowel(char letter)
{
boolean vowel = false;
if(letter == ('a'))
{
return true;
}
return false;
if(letter == ('e'))
{
return true;
}
return false;
if(letter == ('i'))
{
return true;
}
return false;
if(letter == ('o'))
{
return true;
}
return false;
if(letter == ('u'))
{
return true;
}
return false;
return vowel;
}//endproblem3


//problem4
public static String longestWord(String s)
{
int count = 0;
String[] c = s.split(" ");
int longest = c[0].length();
String returnStr = "";
for(int i = 1; i < word.length; i++)
{
if(word[i].length()>=four.length()){
{
longest = c[i].length();
} count = i;
}
}
returnStr = c[count];
return returnStr;
//endproblem4
}
//prob 5
public static void question()
{
Scanner console = new Scanner(System.in);
System.out.println("Which of the following will declare and intialize a variable in Java?");
System.out.println("1. int 1a=4;");
System.out.println("2. double circle-area=5.78;");
System.out.println("3. string s=hello!;");
System.out.println("4. boolean whoaNow = true;");
System.out.print("What is the correct answer? ");
int answer = console.nextInt();
console.nextLine();
switch (userInt){
case 1:System.out.println("Incorrect");
break;
case 2:System.out.println("Incorrect");
break;
case 3:System.out.println("Incorrect");
break;
case 4:System.out.println("Correct");
break;
}
}//end question

public static int daysInMonth(int month, int year)
{

boolean lYear = leapYear(year);
if ((month < 1 || month > 12) && (year < 1 || year > 9999))
{
return 29;
}
else
{
switch(month)
{
case 1:
days = 31;
break;
case 2:
if(year == 1) {
days = 29;
break;
}

case 3:
days = 31;
break;
case 4:
days = 30;
break;
case 5:
days = 31;
break;
case 6:
days = 30;
break;
case 7:
days = 31;
break;
case 8:
days = 31;
break;
case 9:
days = 30;
break;
case 10:
days = 31;
break;
case 11:
days = 30;
break;
case 12:
days = 31;
break;
}
}
}//end daysinMonth

public static boolean leapYear(int year)
{
if(year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
//
}
//
}
//
}
//
}


}
Posted
Updated 12-May-21 2:41am
v2

What's this?
Java
question(System.out.println("Return true if the supplied character is 'a'"));

question is a method you've defined, but it takes no parameters. So why are you combining it with a System.out.println statement?

Are you even attempting to look at your code and figure out what's going wrong or what even looks wrong?
 
Share this answer
 
Comments
Dave Kreskowiak 11-May-21 19:01pm    
and? None of that explains why you put a System.out call inside a parameter list (which doesn't even make sense by the way) to a method that doesn't take any parameters.
Dave Kreskowiak 11-May-21 19:11pm    
What have you been taught about creating a method? Passing parameters? What's the difference between a parameter and an entire statement?

To call question should be just:
    question();
That's it. Nothing inside the parenthesis.
Dave Kreskowiak 11-May-21 19:33pm    
Fix the one problem first, then recompile it.
Dave Kreskowiak 11-May-21 19:48pm    
And?
I can't give you the solution, but do try to format your code with the code button (it's between BIG and var buttons). Right now your code is quite hard to read.

And don't worry about what the solution1 commented. He also trolled my post - in the Internet we often encounter gaslighters who have no friends/family members to troll on. I wish there's a way to block certain users on this platform (I can't find it how).
 
Share this answer
 
Comments
CHill60 12-May-21 8:58am    
Foolish advice. Dave Kreskowiak has clearly spent a lot of his time trying to help the OP - the OP has posted the same question 5 times now and we are all starting to get a little impatient with them. However, Solution 1 and the comments on it are attempting to get the OP to think about what they are doing. That is far more helpful than just giving a solution away.
And if you think the comments here or against your own question were "trolling" then you are going to get some nasty surprises out in the real world
[no name] 12-May-21 9:20am    
Thanks for letting me know what happened to you and the OP. I didn't know that. Mr Kreskowiak gave me comments in "impossible" tones while all the other posters gave me much more mature, professional and productive answers. I only think he spent a lot of time creating an unnecessary conflict. My comment here is only meant to comfort the OP and steer clear of potential conflicts- whatever happened to you and the OP, Mr Kreskowiak's tone has been slanting and not peaceful.
CHill60 12-May-21 11:00am    
Unfortunately it is very difficult to read "tone" in the written word. There are some members here who are considered very rude and very abrupt, they happen to be Russian so an abrupt style is just very natural to them and would not upset anyone in their own country (of origin).
It's nice that you are trying to comfort and reassure the OP - very supportive and I applaud that. It might be better if you do that via the "Have a Question or Comment?" link next time, it will help avoid the downvotes (and trolling)
[no name] 12-May-21 13:10pm    
Sure, I will do that next time if I am only willing to comment not giving any solution. English isn´t my first language so that made me extra difficult to read "tone" in the written word.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900