import java.util.Scanner;
public class Age {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int a;
System.out.println("Input your age");
a = sc.nextInt();
boolean mess = isAllowed(a);
String mess2 = ?isAllowed(a)return"You are allowed to vote";:"You
arent allowed";
String age = personAge(a);
personAge(a);
}
public static String personAge(int age)
{
String mess = "";
if(age<18)
return mess = "You are minor";
else if(age>=18 && age<=22)
return mess = "You are legal you can vote";
else if(age>=22 && age<=60)
return mess = "You are allowed to vote ";
else
return mess = "You are too old";
}
public static boolean isAllowed(int age)
{
if(age>=18)
return true;
else
return false;
}
}
Can someone fix where is my code error. Please Help me.. Fix the code for me..
Dear Student ,
As per requirement submitted above kindly find below solution.
Age.java :
package sample;
//import package
import java.util.Scanner;
//Java class
public class Age {
//main() method
public static void main(String args[]) {
//creating object of Scanner class
Scanner sc = new
Scanner(System.in);
int a;// declaring variable
//asking user age
System.out.println("Input your
age");
a = sc.nextInt();// reading
age
boolean mess = isAllowed(a);//
calling method
String mess2 = isAllowed(a) ? "You
are allowed to vote" : "You arent allowed";
String age = personAge(a);//method
call
personAge(a);
System.out.println(mess2);//print
age
System.out.println(age);//print
age
}
//method to check person age
public static String personAge(int age) {
String mess = "";//declaring
variable
if (age < 18) //if age is less
then 18
return mess =
"You are minor";
else if (age >= 18 &&
age <= 22) //if age is between 18 to 22
return mess =
"You are legal you can vote";
else if (age >= 22 &&
age <= 60) //if age is greater than 22 and less than 60
return mess =
"You are allowed to vote ";
else
return mess =
"You are too old";//return message
}
//method to check age
public static boolean isAllowed(int age) {
// checking age
if (age >= 18)
// if age is
greater than 18
return
true;
else
return
false;
}
}
==================================
Output :Compile and run Age.java to get the screen as shown below
Screen 1:Age.java

Screen 2:

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
import java.util.Scanner; public class Age { public static void main(String args[]) { Scanner sc = new...
import java.util.Scanner; public class SieveOfEratosthenes { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number"); int num = sc.nextInt(); boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false;...
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String inputMonth; int inputDay; inputMonth = scnr.nextString(); inputDay = scnr.nextInt(); String season; if(inputMonth == "April","May","June"){ String season = "Spring"; }else if(inputMonth == "July","August","September"){ String season = "Summer"; }else if(inputMonth == "October","November","December"){ String season = "Autumn"; }else if(inputMonth == "January","February","March"){ System.out.println("Winter"); }else{ System.out.println("Invalid"); } if((inputMonth == "March") && (inputDay >= 20)){ String season = "Spring"; }else if((inputMonth == "June") && (inputDay >= 21)){...
import java.util.Scanner; public class TempConvert { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //ask the user for a temperature System.out.println("Enter a temperature:"); double temp = scnr.nextDouble(); //ask the user for the scale of the temperature System.out.println("Is that Fahrenheit (F) or Celsius (C)?"); char choice = scnr.next().charAt(0); if(choice == 'F') { //convert to Celsius if given temperature was Fahrenheit System.out.println(temp + " degrees Fahrenheit is " + ((5.0/9) * (temp-32)) + " degrees Celsius"); } else {...
public static void main(String[] args) { System.out.println("Welcome to the Future Value Calculator\n"); Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // get the input from the user System.out.println("DATA ENTRY"); double monthlyInvestment = getDoubleWithinRange(sc, "Enter monthly investment: ", 0, 1000); double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 30); int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100); System.out.println(); ...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next(); String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word); if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
import java.util.Scanner; import java.util.ArrayList; public class P3A2_BRANDT_4005916 { public static void main(String[] args) { String name; String answer; int correct = 0; int incorrect = 0; Scanner phantom = new Scanner(System.in); System.out.println("Hello, What is your name?"); name = phantom.nextLine(); System.out.println("Welcome " + name + "!\n"); System.out.println("My name is Danielle Brandt. " +"This is a quiz program that...
import java.util.Scanner; public class EggBasket2 { public static void main (String [] args) { int numberOfBaskets, eggsPerBasket, totalEggs; Scanner keyboard = new Scanner (System.in); System.out.println ("Enter the number of eggs in each basket:"); eggsPerBasket = keyboard.nextInt (); System.out.println ("Enter the number of baskets:"); numberOfBaskets = keyboard.nextInt (); totalEggs = numberOfBaskets * eggsPerBasket; System.out.println ("If you have"); System.out.println (eggsPerBasket + " eggs per basket and"); System.out.println (numberOfBaskets + " baskets, then"); System.out.println ("the total number of eggs is " + totalEggs);...