fork download
  1. import java.io.*;
  2. import java.util.*;
  3. public class Person {
  4. private int age;
  5. private int x;
  6. private int u;
  7. public Person(int age) {
  8. if(age<0){
  9. System.out.println("Age is not valid, setting age to 0.");
  10. age=0;
  11. u=age;
  12. }
  13. else if(age>0)
  14. u=age;
  15. // Add some more code to run some checks on initialAge
  16. }
  17.  
  18. public void amIOld() {
  19.  
  20.  
  21. if(u>=18)
  22. System.out.println("You are old.");
  23. if(u<13)
  24. System.out.println("You are young.");
  25. if(u>=13 && u<18)
  26. System.out.println("You are a teenager.");
  27.  
  28. // Write code determining if this person's age is old and print the correct statement:
  29.  
  30. }
  31.  
  32. public void yearPasses() {
  33. u=u+1;
  34. // Increment this person's age.
  35. }
  36. public static void main(String[] args) {
  37. Scanner sc = new Scanner(System.in);
  38. int T = sc.nextInt();
  39. for (int i = 0; i < T; i++) {
  40. int age = sc.nextInt();
  41. Person p = new Person(age);
  42. p.amIOld();
  43. for (int j = 0; j < 3; j++) {
  44. p.yearPasses();
  45. }
  46. p.amIOld();
  47. System.out.println();
  48. }
  49. sc.close();
  50. }
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class Person is public, should be declared in a file named Person.java
public class Person {
       ^
1 error
stdout
Standard output is empty