1 import java.util.Scanner; // import the Scanner class
   2 import java.util.*
   3 import java.time.LocalDate;// import the LocalDate class
   4 import java.unil.ArrayList;
   5 import java.io.File;
   6 import java.io.IOException;
   7 /* The code is Main Class
   8 */
   9 
  10 abstract class Animal{
  11     //Abstract method
  12     public abstract void animalSound();
  13     //Regular method
  14     public void sleep() {
  15         System.out.println("Zzz");
  16     }
  17 }
  18 
  19 class Pig extends Animal {
  20     public void animalSound(){
  21         System.out.println("The pig says: woo woo");
  22     }
  23 }
  24 
  25 interface Modify {
  26     public void add();
  27     public void delete();
  28     public void move();
  29 }
  30 
  31 class Answer implements Modify {
  32     public void add(){
  33         System.out.println("The answer is: ");
  34     }
  35     public void delete(){
  36         System.out.println("The answer is: ");
  37     }
  38     public void move(){
  39         System.out.println("The answer is: ");
  40     }
  41 }
  42 
  43 
  44 class People{
  45     public void speak_language(){
  46         system.out.println("The people speak a language");
  47     }
  48 }
  49 
  50 class American extends People{
  51     public void speak_language(){
  52         system.out.println("The American speak English");
  53     }
  54 }
  55 
  56 class Chinese extends People{
  57     public void speak_language(){
  58         system.out.println("The Chinese speak Chinese");
  59     }
  60 }
  61 
  62 
  63 public class Fruit{
  64     private String name;
  65 
  66     public String getName(){
  67         return name;
  68     }
  69 
  70     public void setName(String newName){
  71         this.name=newName;
  72     }
  73 }
  74 
  75 public class Main{
  76     int modelYear;
  77     String modelName;
  78 
  79 
  80     public Main(int year, String name) {
  81         modelYear=year; //Set the initial value for the class attribute x
  82         modelName=name;
  83     }
  84 
  85 
  86     enum Level {
  87         LOW,
  88         MEDIUM,
  89         HIGH
  90     }
  91 
  92     public void print_medium(){
  93         Level myVar = Level.MEDIUM;
  94         switch(myVar){
  95         case LOW:
  96             System.out.println("Low Level")
  97             break;
  98         case MEDIUM:
  99             System.out.println("Medium Level")
 100             break;
 101         case HIGH:
 102             System.out.println("HIGH Level")
 103             break;
 104         }
 105     }
 106 
 107     public void scan_info(){
 108         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 109 
 110         System.out.println("Enter name, age and salary:");
 111 
 112         //String input
 113 
 114         String name = myObj.nextline();
 115 
 116         //Numberical input
 117         int age =myObj.nextInt();
 118         double salary = myObj.nextDouble();
 119 
 120  121         //Output input by user
 122         System.out.println("Name: "+ name);
 123         System.out.println("Age: "+ age);
 124         System.out.println("Salary: "+ salary);
 125 
 126     }
 127 
 128     public void display_formatted_date_time(){
 129         LocalDateTime myDateObj = LocalDateTime.now();
 130         System.out.println("Before formatting: "+myDateObj);
 131         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 132 
 133         String formattedDate=myDateObj.format(myFormatObj);
 134         System.out.println("After formatting: " + formattedDate);
 135     }
 136 
 137 
 138     public static int sum(int k){
 139         if(k>0){
 140             return k+sum(k-1);
 141         }else{
 142             return 0;
 143         }
 144     }
 145 
 146     public static void main(String[] args) {
 147 
 148         int result=sum(10);
 149         System.out.print(result);
 150 
 151         scan_info();
 152         display_formatted_date_time();
 153         print_medium();
 154 
 155         Fruit apple=new Fruit();
 156         apple.setName("Apple");
 157         System.out.println(apple.getName());
 158 
 159         Main myMain=new Main(1969, "Mustang");
 160         System.out.println(myMain.modelYear+" "+myMain.modelName);
 161 
 162         Pig myPig=new Pig();
 163         myPig.animalSound();
 164         myPig.sleep();
 165 
 166         Answer myModi=new Answer();
 167         myModi.add();
 168         myModi.delete();
 169         myModi.move();
 170 
 171         People people=new People();
 172         People american=new American();
 173         People chinese=new Chinese();
 174         people.speak_language();
 175         american.speak_language();
 176         chinese.speak_language();
 177 
 178         ArrayList cars=new ArrayList();
 179         cars.add("Volvo");
 180         cars.add("BMW");
 181         cars.add("Ford");
 182         cars.add("Mazda");
 183         System.out.println(cars);
 184 
 185         try{
 186             File myFile=new File("filename.txt");
 187             if (myFile.createNewFile()){
 188                 system.out.println("File created: " + myFile.getName());
 189             }else{
 190                 System.out.println("File already exists.");
 191             }
 192         }catch (IOException e) {
 193             System.out.println("An error occurred.");
 194             e.printStackTrace();
 195         }
 196 
 197         try{
 198             FileWriter myWriter = new FileWriter("filename.txt");
 199             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 200             myWriter,close();
 201             System.out.println("Successfully wrote to the file.");
 202         }catch(IOException e) {
 203             System.out.println("An error occurred.");
 204             e.printStackTrace();
 205         }
 206     }
 207 }
 208 import java.util.Scanner; // import the Scanner class
 209 import java.util.*
 210 import java.time.LocalDate;// import the LocalDate class
 211 import java.unil.ArrayList;
 212 import java.io.File;
 213 import java.io.IOException;
 214 /* The code is Main Class
 215 */
 216 
 217 abstract class Animal{
 218     //Abstract method
 219     public abstract void animalSound();
 220     //Regular method
 221     public void sleep() {
 222         System.out.println("Zzz");
 223     }
 224 }
 225 
 226 class Pig extends Animal {
 227     public void animalSound(){
 228         System.out.println("The pig says: woo woo");
 229     }
 230 }
 231 
 232 interface Modify {
 233     public void add();
 234     public void delete();
 235     public void move();
 236 }
 237 
 238 class Answer implements Modify {
 239     public void add(){
 240         System.out.println("The answer is: ");
 241     }
 242     public void delete(){
 243         System.out.println("The answer is: ");
 244     }
 245     public void move(){
 246         System.out.println("The answer is: ");
 247     }
 248 }
 249 
 250 
 251 class People{
 252     public void speak_language(){
 253         system.out.println("The people speak a language");
 254     }
 255 }
 256 
 257 class American extends People{
 258     public void speak_language(){
 259         system.out.println("The American speak English");
 260     }
 261 }
 262 
 263 class Chinese extends People{
 264     public void speak_language(){
 265         system.out.println("The Chinese speak Chinese");
 266     }
 267 }
 268 
 269 
 270 public class Fruit{
 271     private String name;
 272 
 273     public String getName(){
 274         return name;
 275     }
 276 
 277     public void setName(String newName){
 278         this.name=newName;
 279     }
 280 }
 281 
 282 public class Main{
 283     int modelYear;
 284     String modelName;
 285 
 286 
 287     public Main(int year, String name) {
 288         modelYear=year; //Set the initial value for the class attribute x
 289         modelName=name;
 290     }
 291 
 292 
 293     enum Level {
 294         LOW,
 295         MEDIUM,
 296         HIGH
 297     }
 298 
 299     public void print_medium(){
 300         Level myVar = Level.MEDIUM;
 301         switch(myVar){
 302         case LOW:
 303             System.out.println("Low Level")
 304             break;
 305         case MEDIUM:
 306             System.out.println("Medium Level")
 307             break;
 308         case HIGH:
 309             System.out.println("HIGH Level")
 310             break;
 311         }
 312     }
 313 
 314     public void scan_info(){
 315         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 316 
 317         System.out.println("Enter name, age and salary:");
 318 
 319         //String input
 320 
 321         String name = myObj.nextline();
 322 
 323         //Numberical input
 324         int age =myObj.nextInt();
 325         double salary = myObj.nextDouble();
 326 
 327  328         //Output input by user
 329         System.out.println("Name: "+ name);
 330         System.out.println("Age: "+ age);
 331         System.out.println("Salary: "+ salary);
 332 
 333     }
 334 
 335     public void display_formatted_date_time(){
 336         LocalDateTime myDateObj = LocalDateTime.now();
 337         System.out.println("Before formatting: "+myDateObj);
 338         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 339 
 340         String formattedDate=myDateObj.format(myFormatObj);
 341         System.out.println("After formatting: " + formattedDate);
 342     }
 343 
 344 
 345     public static int sum(int k){
 346         if(k>0){
 347             return k+sum(k-1);
 348         }else{
 349             return 0;
 350         }
 351     }
 352 
 353     public static void main(String[] args) {
 354 
 355         int result=sum(10);
 356         System.out.print(result);
 357 
 358         scan_info();
 359         display_formatted_date_time();
 360         print_medium();
 361 
 362         Fruit apple=new Fruit();
 363         apple.setName("Apple");
 364         System.out.println(apple.getName());
 365 
 366         Main myMain=new Main(1969, "Mustang");
 367         System.out.println(myMain.modelYear+" "+myMain.modelName);
 368 
 369         Pig myPig=new Pig();
 370         myPig.animalSound();
 371         myPig.sleep();
 372 
 373         Answer myModi=new Answer();
 374         myModi.add();
 375         myModi.delete();
 376         myModi.move();
 377 
 378         People people=new People();
 379         People american=new American();
 380         People chinese=new Chinese();
 381         people.speak_language();
 382         american.speak_language();
 383         chinese.speak_language();
 384 
 385         ArrayList cars=new ArrayList();
 386         cars.add("Volvo");
 387         cars.add("BMW");
 388         cars.add("Ford");
 389         cars.add("Mazda");
 390         System.out.println(cars);
 391 
 392         try{
 393             File myFile=new File("filename.txt");
 394             if (myFile.createNewFile()){
 395                 system.out.println("File created: " + myFile.getName());
 396             }else{
 397                 System.out.println("File already exists.");
 398             }
 399         }catch (IOException e) {
 400             System.out.println("An error occurred.");
 401             e.printStackTrace();
 402         }
 403 
 404         try{
 405             FileWriter myWriter = new FileWriter("filename.txt");
 406             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 407             myWriter,close();
 408             System.out.println("Successfully wrote to the file.");
 409         }catch(IOException e) {
 410             System.out.println("An error occurred.");
 411             e.printStackTrace();
 412         }
 413     }
 414 }
 415 import java.util.Scanner; // import the Scanner class
 416 import java.util.*
 417 import java.time.LocalDate;// import the LocalDate class
 418 import java.unil.ArrayList;
 419 import java.io.File;
 420 import java.io.IOException;
 421 /* The code is Main Class
 422 */
 423 
 424 abstract class Animal{
 425     //Abstract method
 426     public abstract void animalSound();
 427     //Regular method
 428     public void sleep() {
 429         System.out.println("Zzz");
 430     }
 431 }
 432 
 433 class Pig extends Animal {
 434     public void animalSound(){
 435         System.out.println("The pig says: woo woo");
 436     }
 437 }
 438 
 439 interface Modify {
 440     public void add();
 441     public void delete();
 442     public void move();
 443 }
 444 
 445 class Answer implements Modify {
 446     public void add(){
 447         System.out.println("The answer is: ");
 448     }
 449     public void delete(){
 450         System.out.println("The answer is: ");
 451     }
 452     public void move(){
 453         System.out.println("The answer is: ");
 454     }
 455 }
 456 
 457 
 458 class People{
 459     public void speak_language(){
 460         system.out.println("The people speak a language");
 461     }
 462 }
 463 
 464 class American extends People{
 465     public void speak_language(){
 466         system.out.println("The American speak English");
 467     }
 468 }
 469 
 470 class Chinese extends People{
 471     public void speak_language(){
 472         system.out.println("The Chinese speak Chinese");
 473     }
 474 }
 475 
 476 
 477 public class Fruit{
 478     private String name;
 479 
 480     public String getName(){
 481         return name;
 482     }
 483 
 484     public void setName(String newName){
 485         this.name=newName;
 486     }
 487 }
 488 
 489 public class Main{
 490     int modelYear;
 491     String modelName;
 492 
 493 
 494     public Main(int year, String name) {
 495         modelYear=year; //Set the initial value for the class attribute x
 496         modelName=name;
 497     }
 498 
 499 
 500     enum Level {
 501         LOW,
 502         MEDIUM,
 503         HIGH
 504     }
 505 
 506     public void print_medium(){
 507         Level myVar = Level.MEDIUM;
 508         switch(myVar){
 509         case LOW:
 510             System.out.println("Low Level")
 511             break;
 512         case MEDIUM:
 513             System.out.println("Medium Level")
 514             break;
 515         case HIGH:
 516             System.out.println("HIGH Level")
 517             break;
 518         }
 519     }
 520 
 521     public void scan_info(){
 522         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 523 
 524         System.out.println("Enter name, age and salary:");
 525 
 526         //String input
 527 
 528         String name = myObj.nextline();
 529 
 530         //Numberical input
 531         int age =myObj.nextInt();
 532         double salary = myObj.nextDouble();
 533 
 534  535         //Output input by user
 536         System.out.println("Name: "+ name);
 537         System.out.println("Age: "+ age);
 538         System.out.println("Salary: "+ salary);
 539 
 540     }
 541 
 542     public void display_formatted_date_time(){
 543         LocalDateTime myDateObj = LocalDateTime.now();
 544         System.out.println("Before formatting: "+myDateObj);
 545         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 546 
 547         String formattedDate=myDateObj.format(myFormatObj);
 548         System.out.println("After formatting: " + formattedDate);
 549     }
 550 
 551 
 552     public static int sum(int k){
 553         if(k>0){
 554             return k+sum(k-1);
 555         }else{
 556             return 0;
 557         }
 558     }
 559 
 560     public static void main(String[] args) {
 561 
 562         int result=sum(10);
 563         System.out.print(result);
 564 
 565         scan_info();
 566         display_formatted_date_time();
 567         print_medium();
 568 
 569         Fruit apple=new Fruit();
 570         apple.setName("Apple");
 571         System.out.println(apple.getName());
 572 
 573         Main myMain=new Main(1969, "Mustang");
 574         System.out.println(myMain.modelYear+" "+myMain.modelName);
 575 
 576         Pig myPig=new Pig();
 577         myPig.animalSound();
 578         myPig.sleep();
 579 
 580         Answer myModi=new Answer();
 581         myModi.add();
 582         myModi.delete();
 583         myModi.move();
 584 
 585         People people=new People();
 586         People american=new American();
 587         People chinese=new Chinese();
 588         people.speak_language();
 589         american.speak_language();
 590         chinese.speak_language();
 591 
 592         ArrayList cars=new ArrayList();
 593         cars.add("Volvo");
 594         cars.add("BMW");
 595         cars.add("Ford");
 596         cars.add("Mazda");
 597         System.out.println(cars);
 598 
 599         try{
 600             File myFile=new File("filename.txt");
 601             if (myFile.createNewFile()){
 602                 system.out.println("File created: " + myFile.getName());
 603             }else{
 604                 System.out.println("File already exists.");
 605             }
 606         }catch (IOException e) {
 607             System.out.println("An error occurred.");
 608             e.printStackTrace();
 609         }
 610 
 611         try{
 612             FileWriter myWriter = new FileWriter("filename.txt");
 613             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 614             myWriter,close();
 615             System.out.println("Successfully wrote to the file.");
 616         }catch(IOException e) {
 617             System.out.println("An error occurred.");
 618             e.printStackTrace();
 619         }
 620     }
 621 }
 622 import java.util.Scanner; // import the Scanner class
 623 import java.util.*
 624 import java.time.LocalDate;// import the LocalDate class
 625 import java.unil.ArrayList;
 626 import java.io.File;
 627 import java.io.IOException;
 628 /* The code is Main Class
 629 */
 630 
 631 abstract class Animal{
 632     //Abstract method
 633     public abstract void animalSound();
 634     //Regular method
 635     public void sleep() {
 636         System.out.println("Zzz");
 637     }
 638 }
 639 
 640 class Pig extends Animal {
 641     public void animalSound(){
 642         System.out.println("The pig says: woo woo");
 643     }
 644 }
 645 
 646 interface Modify {
 647     public void add();
 648     public void delete();
 649     public void move();
 650 }
 651 
 652 class Answer implements Modify {
 653     public void add(){
 654         System.out.println("The answer is: ");
 655     }
 656     public void delete(){
 657         System.out.println("The answer is: ");
 658     }
 659     public void move(){
 660         System.out.println("The answer is: ");
 661     }
 662 }
 663 
 664 
 665 class People{
 666     public void speak_language(){
 667         system.out.println("The people speak a language");
 668     }
 669 }
 670 
 671 class American extends People{
 672     public void speak_language(){
 673         system.out.println("The American speak English");
 674     }
 675 }
 676 
 677 class Chinese extends People{
 678     public void speak_language(){
 679         system.out.println("The Chinese speak Chinese");
 680     }
 681 }
 682 
 683 
 684 public class Fruit{
 685     private String name;
 686 
 687     public String getName(){
 688         return name;
 689     }
 690 
 691     public void setName(String newName){
 692         this.name=newName;
 693     }
 694 }
 695 
 696 public class Main{
 697     int modelYear;
 698     String modelName;
 699 
 700 
 701     public Main(int year, String name) {
 702         modelYear=year; //Set the initial value for the class attribute x
 703         modelName=name;
 704     }
 705 
 706 
 707     enum Level {
 708         LOW,
 709         MEDIUM,
 710         HIGH
 711     }
 712 
 713     public void print_medium(){
 714         Level myVar = Level.MEDIUM;
 715         switch(myVar){
 716         case LOW:
 717             System.out.println("Low Level")
 718             break;
 719         case MEDIUM:
 720             System.out.println("Medium Level")
 721             break;
 722         case HIGH:
 723             System.out.println("HIGH Level")
 724             break;
 725         }
 726     }
 727 
 728     public void scan_info(){
 729         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 730 
 731         System.out.println("Enter name, age and salary:");
 732 
 733         //String input
 734 
 735         String name = myObj.nextline();
 736 
 737         //Numberical input
 738         int age =myObj.nextInt();
 739         double salary = myObj.nextDouble();
 740 
 741  742         //Output input by user
 743         System.out.println("Name: "+ name);
 744         System.out.println("Age: "+ age);
 745         System.out.println("Salary: "+ salary);
 746 
 747     }
 748 
 749     public void display_formatted_date_time(){
 750         LocalDateTime myDateObj = LocalDateTime.now();
 751         System.out.println("Before formatting: "+myDateObj);
 752         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 753 
 754         String formattedDate=myDateObj.format(myFormatObj);
 755         System.out.println("After formatting: " + formattedDate);
 756     }
 757 
 758 
 759     public static int sum(int k){
 760         if(k>0){
 761             return k+sum(k-1);
 762         }else{
 763             return 0;
 764         }
 765     }
 766 
 767     public static void main(String[] args) {
 768 
 769         int result=sum(10);
 770         System.out.print(result);
 771 
 772         scan_info();
 773         display_formatted_date_time();
 774         print_medium();
 775 
 776         Fruit apple=new Fruit();
 777         apple.setName("Apple");
 778         System.out.println(apple.getName());
 779 
 780         Main myMain=new Main(1969, "Mustang");
 781         System.out.println(myMain.modelYear+" "+myMain.modelName);
 782 
 783         Pig myPig=new Pig();
 784         myPig.animalSound();
 785         myPig.sleep();
 786 
 787         Answer myModi=new Answer();
 788         myModi.add();
 789         myModi.delete();
 790         myModi.move();
 791 
 792         People people=new People();
 793         People american=new American();
 794         People chinese=new Chinese();
 795         people.speak_language();
 796         american.speak_language();
 797         chinese.speak_language();
 798 
 799         ArrayList cars=new ArrayList();
 800         cars.add("Volvo");
 801         cars.add("BMW");
 802         cars.add("Ford");
 803         cars.add("Mazda");
 804         System.out.println(cars);
 805 
 806         try{
 807             File myFile=new File("filename.txt");
 808             if (myFile.createNewFile()){
 809                 system.out.println("File created: " + myFile.getName());
 810             }else{
 811                 System.out.println("File already exists.");
 812             }
 813         }catch (IOException e) {
 814             System.out.println("An error occurred.");
 815             e.printStackTrace();
 816         }
 817 
 818         try{
 819             FileWriter myWriter = new FileWriter("filename.txt");
 820             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 821             myWriter,close();
 822             System.out.println("Successfully wrote to the file.");
 823         }catch(IOException e) {
 824             System.out.println("An error occurred.");
 825             e.printStackTrace();
 826         }
 827     }
 828 }
 829 import java.util.Scanner; // import the Scanner class
 830 import java.util.*
 831 import java.time.LocalDate;// import the LocalDate class
 832 import java.unil.ArrayList;
 833 import java.io.File;
 834 import java.io.IOException;
 835 /* The code is Main Class
 836 */
 837 
 838 abstract class Animal{
 839     //Abstract method
 840     public abstract void animalSound();
 841     //Regular method
 842     public void sleep() {
 843         System.out.println("Zzz");
 844     }
 845 }
 846 
 847 class Pig extends Animal {
 848     public void animalSound(){
 849         System.out.println("The pig says: woo woo");
 850     }
 851 }
 852 
 853 interface Modify {
 854     public void add();
 855     public void delete();
 856     public void move();
 857 }
 858 
 859 class Answer implements Modify {
 860     public void add(){
 861         System.out.println("The answer is: ");
 862     }
 863     public void delete(){
 864         System.out.println("The answer is: ");
 865     }
 866     public void move(){
 867         System.out.println("The answer is: ");
 868     }
 869 }
 870 
 871 
 872 class People{
 873     public void speak_language(){
 874         system.out.println("The people speak a language");
 875     }
 876 }
 877 
 878 class American extends People{
 879     public void speak_language(){
 880         system.out.println("The American speak English");
 881     }
 882 }
 883 
 884 class Chinese extends People{
 885     public void speak_language(){
 886         system.out.println("The Chinese speak Chinese");
 887     }
 888 }
 889 
 890 
 891 public class Fruit{
 892     private String name;
 893 
 894     public String getName(){
 895         return name;
 896     }
 897 
 898     public void setName(String newName){
 899         this.name=newName;
 900     }
 901 }
 902 
 903 public class Main{
 904     int modelYear;
 905     String modelName;
 906 
 907 
 908     public Main(int year, String name) {
 909         modelYear=year; //Set the initial value for the class attribute x
 910         modelName=name;
 911     }
 912 
 913 
 914     enum Level {
 915         LOW,
 916         MEDIUM,
 917         HIGH
 918     }
 919 
 920     public void print_medium(){
 921         Level myVar = Level.MEDIUM;
 922         switch(myVar){
 923         case LOW:
 924             System.out.println("Low Level")
 925             break;
 926         case MEDIUM:
 927             System.out.println("Medium Level")
 928             break;
 929         case HIGH:
 930             System.out.println("HIGH Level")
 931             break;
 932         }
 933     }
 934 
 935     public void scan_info(){
 936         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 937 
 938         System.out.println("Enter name, age and salary:");
 939 
 940         //String input
 941 
 942         String name = myObj.nextline();
 943 
 944         //Numberical input
 945         int age =myObj.nextInt();
 946         double salary = myObj.nextDouble();
 947 
 948  949         //Output input by user
 950         System.out.println("Name: "+ name);
 951         System.out.println("Age: "+ age);
 952         System.out.println("Salary: "+ salary);
 953 
 954     }
 955 
 956     public void display_formatted_date_time(){
 957         LocalDateTime myDateObj = LocalDateTime.now();
 958         System.out.println("Before formatting: "+myDateObj);
 959         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 960 
 961         String formattedDate=myDateObj.format(myFormatObj);
 962         System.out.println("After formatting: " + formattedDate);
 963     }
 964 
 965 
 966     public static int sum(int k){
 967         if(k>0){
 968             return k+sum(k-1);
 969         }else{
 970             return 0;
 971         }
 972     }
 973 
 974     public static void main(String[] args) {
 975 
 976         int result=sum(10);
 977         System.out.print(result);
 978 
 979         scan_info();
 980         display_formatted_date_time();
 981         print_medium();
 982 
 983         Fruit apple=new Fruit();
 984         apple.setName("Apple");
 985         System.out.println(apple.getName());
 986 
 987         Main myMain=new Main(1969, "Mustang");
 988         System.out.println(myMain.modelYear+" "+myMain.modelName);
 989 
 990         Pig myPig=new Pig();
 991         myPig.animalSound();
 992         myPig.sleep();
 993 
 994         Answer myModi=new Answer();
 995         myModi.add();
 996         myModi.delete();
 997         myModi.move();
 998 
 999         People people=new People();
1000         People american=new American();
1001         People chinese=new Chinese();
1002         people.speak_language();
1003         american.speak_language();
1004         chinese.speak_language();
1005 
1006         ArrayList cars=new ArrayList();
1007         cars.add("Volvo");
1008         cars.add("BMW");
1009         cars.add("Ford");
1010         cars.add("Mazda");
1011         System.out.println(cars);
1012 
1013         try{
1014             File myFile=new File("filename.txt");
1015             if (myFile.createNewFile()){
1016                 system.out.println("File created: " + myFile.getName());
1017             }else{
1018                 System.out.println("File already exists.");
1019             }
1020         }catch (IOException e) {
1021             System.out.println("An error occurred.");
1022             e.printStackTrace();
1023         }
1024 
1025         try{
1026             FileWriter myWriter = new FileWriter("filename.txt");
1027             myWriter.write("Files in Java might be tricky, but it is fun enough!");
1028             myWriter,close();
1029             System.out.println("Successfully wrote to the file.");
1030         }catch(IOException e) {
1031             System.out.println("An error occurred.");
1032             e.printStackTrace();
1033         }
1034     }
1035 }
1036 

deleted moved changed
   1 import java.util.Scanner; // import the Scanner class
   2 import java.time.LocalDate;// import the LocalDate class
   3 import java.unil.ArrayList;
   4 import java.io.File;
   5 import java.io.IOException;
   6 /* The code is Main Class
   7 */
   8 
   9 abstract class Animal{
  10     //Abstract method
  11     public abstract void animalSound();
  12     //Regular method
  13     public void sleep() {
  14         System.out.println("Zzz");
  15     }
  16 }
  17 
  18 class Pig extends Animal {
  19     public void animalSound(){
  20         System.out.println("The pig says: woo woo");
  21     }
  22 }
  23 
  24 interface Modify {
  25     public void add();
  26     public void delete();
  27     public void move();
  28 }
  29 
  30 class Answer implements Modify {
  31     public void add(){
  32         System.out.println("The answer is that: ");
  33     }
  34     public void delete(){
  35         System.out.println("The answer is: ");
  36     }
  37     public void move(){
  38         System.out.println("The answer is: ");
  39     }
  40 }
  41 
  42 
  43 class People{
  44     public void speak_language(){
  45         system.out.println("The people speak a language");
  46     }
  47 }
  48 
  49 class American extends People{
  50     public void speak_language(){
  51         system.out.println("The American speak English");
  52     }
  53 }
  54 
  55 class Chinese extends People{
  56     public void speak_language(){
  57         system.out.println("The Chinese speak Chinese");
  58     }
  59 }
  60 
  61 
  62   63 public class Fruit{
  64     private String name;
  65 
  66     public String getName(){
  67         return name;
  68     }
  69 
  70     public void setName(String newName){
  71         this.name=newName;
  72     }
  73 }
  74 
  75 public class Main{
  76     int modelYears;
  77     String modelName;
  78 
  79 
  80     public Main(int year, String name) {
  81         modelYears=year; //Set the initial value for the class attribute x
  82         modelName=name;
  83     }
  84 
  85 
  86     enum Level {
  87         LOW,
  88         MEDIUM,
  89         HIGH
  90     }
  91 
  92     public void print_medium(){
  93         Level myVar = Level.MEDIUM;
  94         switch(myVar){
  95         case LOW:
  96             System.out.println("Low Level")
  97             break;
  98         case MEDIUM:
  99             System.out.println("Medium Level")
 100             break;
 101         case HIGH:
 102             System.out.println("HIGH Level")
 103             break;
 104         }
 105     }
 106 
 107     public void scan_info(){
 108         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 109 
 110         System.out.println("Enter name, age and salary:");
 111 
 112         //String input
 113 
 114         String name = myObj.nextline();
 115 
 116         //Numberical input
 117         int age =myObj.nextInt();
 118         double salary = myObj.nextDouble();
 119 
 120         //Output input by user
 121         System.out.println("Name: "+ name);
 122         System.out.println("Age: "+ age);
 123         System.out.println("Salary: "+ salary);
 124 
 125     }
 126 
 127     public void display_formatted_date_time(){
 128         LocalDateTime myDateObj = LocalDateTime.now();
 129         System.out.println("Before formatting: "+myDateObj);
 130         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 131 
 132         String formattedDate=myDateObj.format(myFormatObj);
 133         System.out.println("After formatting: " + formattedDate);
 134     }
 135 
 136 
 137     public static int sum(int k){
 138         if(k>0){
 139             return k+sum(k-1);
 140         }else{
 141             return 0;
 142         }
 143     }
 144 
 145     public static void main(String[] args) {
 146 
 147         int result=sum(10);
 148         System.out.print(result);
 149 
 150         scan_info();
 151         display_formatted_date_time();
 152         print_medium();
 153 
 154         Fruit orange=new Fruit();
 155         orange.setName("Orange");
 156         System.out.println(apple.getName());
 157 
 158         Main myMain=new Main(1970, "Sun");
 159         System.out.println(myMain.modelYear+" "+myMain.modelName);
 160 
 161         Pig myPig_r=new Pig();
 162         myPig_r.animalSound();
 163         myPig_r.sleep();
 164 
 165         Answer myModi=new Answer();
 166         myModi.add();
 167         myModi.delete();
 168         myModi.move();
 169 
 170         People people=new People();
 171         People american=new American();
 172         People chinese=new Chinese();
 173         people.speak_language();
 174         american.speak_language();
 175         chinese.speak_language();
 176 
 177         ArrayList cars=new ArrayList();
 178         cars.add("BMW");
 179         cars.add("Volvo");
 180         cars.add("Mazda");
 181         cars.add("Ford");
 182         cars.add("Toyota")
 183         System.out.println(cars);
 184 
 185         try{
 186             File myFile=new File("filename.txt");
 187             if (myFile.createNewFile()){
 188                 system.out.println("File created: " + myFile.getName());
 189             }else{
 190                 System.out.println("File already exists.");
 191             }
 192         }catch (IOException e) {
 193             System.out.println("An error occurred.");
 194             e.printStackTrace();
 195         }
 196 
 197         try{
 198             FileWriter myWriter = new FileWriter("filename.txt");
 199             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 200             myWriter,close();
 201             System.out.println("Successfully wrote to the file.");
 202         }catch(IOException e) {
 203             System.out.println("An error occurred.");
 204             e.printStackTrace();
 205         }
 206     }
 207 }
 208 import java.util.Scanner; // import the Scanner class
 209 import java.time.LocalDate;// import the LocalDate class
 210 import java.unil.ArrayList;
 211 import java.io.File;
 212 import java.io.IOException;
 213 /* The code is Main Class
 214 */
 215 
 216 abstract class Animal{
 217     //Abstract method
 218     public abstract void animalSound();
 219     //Regular method
 220     public void sleep() {
 221         System.out.println("Zzz");
 222     }
 223 }
 224 
 225 class Pig extends Animal {
 226     public void animalSound(){
 227         System.out.println("The pig says: woo woo");
 228     }
 229 }
 230 
 231 interface Modify {
 232     public void add();
 233     public void delete();
 234     public void move();
 235 }
 236 
 237 class Answer implements Modify {
 238     public void add(){
 239         System.out.println("The answer is that: ");
 240     }
 241     public void delete(){
 242         System.out.println("The answer is: ");
 243     }
 244     public void move(){
 245         System.out.println("The answer is: ");
 246     }
 247 }
 248 
 249 
 250 class People{
 251     public void speak_language(){
 252         system.out.println("The people speak a language");
 253     }
 254 }
 255 
 256 class American extends People{
 257     public void speak_language(){
 258         system.out.println("The American speak English");
 259     }
 260 }
 261 
 262 class Chinese extends People{
 263     public void speak_language(){
 264         system.out.println("The Chinese speak Chinese");
 265     }
 266 }
 267 
 268 
 269  270 public class Fruit{
 271     private String name;
 272 
 273     public String getName(){
 274         return name;
 275     }
 276 
 277     public void setName(String newName){
 278         this.name=newName;
 279     }
 280 }
 281 
 282 public class Main{
 283     int modelYears;
 284     String modelName;
 285 
 286 
 287     public Main(int year, String name) {
 288         modelYears=year; //Set the initial value for the class attribute x
 289         modelName=name;
 290     }
 291 
 292 
 293     enum Level {
 294         LOW,
 295         MEDIUM,
 296         HIGH
 297     }
 298 
 299     public void print_medium(){
 300         Level myVar = Level.MEDIUM;
 301         switch(myVar){
 302         case LOW:
 303             System.out.println("Low Level")
 304             break;
 305         case MEDIUM:
 306             System.out.println("Medium Level")
 307             break;
 308         case HIGH:
 309             System.out.println("HIGH Level")
 310             break;
 311         }
 312     }
 313 
 314     public void scan_info(){
 315         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 316 
 317         System.out.println("Enter name, age and salary:");
 318 
 319         //String input
 320 
 321         String name = myObj.nextline();
 322 
 323         //Numberical input
 324         int age =myObj.nextInt();
 325         double salary = myObj.nextDouble();
 326 
 327         //Output input by user
 328         System.out.println("Name: "+ name);
 329         System.out.println("Age: "+ age);
 330         System.out.println("Salary: "+ salary);
 331 
 332     }
 333 
 334     public void display_formatted_date_time(){
 335         LocalDateTime myDateObj = LocalDateTime.now();
 336         System.out.println("Before formatting: "+myDateObj);
 337         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 338 
 339         String formattedDate=myDateObj.format(myFormatObj);
 340         System.out.println("After formatting: " + formattedDate);
 341     }
 342 
 343 
 344     public static int sum(int k){
 345         if(k>0){
 346             return k+sum(k-1);
 347         }else{
 348             return 0;
 349         }
 350     }
 351 
 352     public static void main(String[] args) {
 353 
 354         int result=sum(10);
 355         System.out.print(result);
 356 
 357         scan_info();
 358         display_formatted_date_time();
 359         print_medium();
 360 
 361         Fruit orange=new Fruit();
 362         orange.setName("Orange");
 363         System.out.println(apple.getName());
 364 
 365         Main myMain=new Main(1970, "Sun");
 366         System.out.println(myMain.modelYear+" "+myMain.modelName);
 367 
 368         Pig myPig_r=new Pig();
 369         myPig_r.animalSound();
 370         myPig_r.sleep();
 371 
 372         Answer myModi=new Answer();
 373         myModi.add();
 374         myModi.delete();
 375         myModi.move();
 376 
 377         People people=new People();
 378         People american=new American();
 379         People chinese=new Chinese();
 380         people.speak_language();
 381         american.speak_language();
 382         chinese.speak_language();
 383 
 384         ArrayList cars=new ArrayList();
 385         cars.add("BMW");
 386         cars.add("Volvo");
 387         cars.add("Mazda");
 388         cars.add("Ford");
 389         cars.add("Toyota")
 390         System.out.println(cars);
 391 
 392         try{
 393             File myFile=new File("filename.txt");
 394             if (myFile.createNewFile()){
 395                 system.out.println("File created: " + myFile.getName());
 396             }else{
 397                 System.out.println("File already exists.");
 398             }
 399         }catch (IOException e) {
 400             System.out.println("An error occurred.");
 401             e.printStackTrace();
 402         }
 403 
 404         try{
 405             FileWriter myWriter = new FileWriter("filename.txt");
 406             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 407             myWriter,close();
 408             System.out.println("Successfully wrote to the file.");
 409         }catch(IOException e) {
 410             System.out.println("An error occurred.");
 411             e.printStackTrace();
 412         }
 413     }
 414 }
 415 import java.util.Scanner; // import the Scanner class
 416 import java.time.LocalDate;// import the LocalDate class
 417 import java.unil.ArrayList;
 418 import java.io.File;
 419 import java.io.IOException;
 420 /* The code is Main Class
 421 */
 422 
 423 abstract class Animal{
 424     //Abstract method
 425     public abstract void animalSound();
 426     //Regular method
 427     public void sleep() {
 428         System.out.println("Zzz");
 429     }
 430 }
 431 
 432 class Pig extends Animal {
 433     public void animalSound(){
 434         System.out.println("The pig says: woo woo");
 435     }
 436 }
 437 
 438 interface Modify {
 439     public void add();
 440     public void delete();
 441     public void move();
 442 }
 443 
 444 class Answer implements Modify {
 445     public void add(){
 446         System.out.println("The answer is that: ");
 447     }
 448     public void delete(){
 449         System.out.println("The answer is: ");
 450     }
 451     public void move(){
 452         System.out.println("The answer is: ");
 453     }
 454 }
 455 
 456 
 457 class People{
 458     public void speak_language(){
 459         system.out.println("The people speak a language");
 460     }
 461 }
 462 
 463 class American extends People{
 464     public void speak_language(){
 465         system.out.println("The American speak English");
 466     }
 467 }
 468 
 469 class Chinese extends People{
 470     public void speak_language(){
 471         system.out.println("The Chinese speak Chinese");
 472     }
 473 }
 474 
 475 
 476  477 public class Fruit{
 478     private String name;
 479 
 480     public String getName(){
 481         return name;
 482     }
 483 
 484     public void setName(String newName){
 485         this.name=newName;
 486     }
 487 }
 488 
 489 public class Main{
 490     int modelYears;
 491     String modelName;
 492 
 493 
 494     public Main(int year, String name) {
 495         modelYears=year; //Set the initial value for the class attribute x
 496         modelName=name;
 497     }
 498 
 499 
 500     enum Level {
 501         LOW,
 502         MEDIUM,
 503         HIGH
 504     }
 505 
 506     public void print_medium(){
 507         Level myVar = Level.MEDIUM;
 508         switch(myVar){
 509         case LOW:
 510             System.out.println("Low Level")
 511             break;
 512         case MEDIUM:
 513             System.out.println("Medium Level")
 514             break;
 515         case HIGH:
 516             System.out.println("HIGH Level")
 517             break;
 518         }
 519     }
 520 
 521     public void scan_info(){
 522         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 523 
 524         System.out.println("Enter name, age and salary:");
 525 
 526         //String input
 527 
 528         String name = myObj.nextline();
 529 
 530         //Numberical input
 531         int age =myObj.nextInt();
 532         double salary = myObj.nextDouble();
 533 
 534         //Output input by user
 535         System.out.println("Name: "+ name);
 536         System.out.println("Age: "+ age);
 537         System.out.println("Salary: "+ salary);
 538 
 539     }
 540 
 541     public void display_formatted_date_time(){
 542         LocalDateTime myDateObj = LocalDateTime.now();
 543         System.out.println("Before formatting: "+myDateObj);
 544         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 545 
 546         String formattedDate=myDateObj.format(myFormatObj);
 547         System.out.println("After formatting: " + formattedDate);
 548     }
 549 
 550 
 551     public static int sum(int k){
 552         if(k>0){
 553             return k+sum(k-1);
 554         }else{
 555             return 0;
 556         }
 557     }
 558 
 559     public static void main(String[] args) {
 560 
 561         int result=sum(10);
 562         System.out.print(result);
 563 
 564         scan_info();
 565         display_formatted_date_time();
 566         print_medium();
 567 
 568         Fruit orange=new Fruit();
 569         orange.setName("Orange");
 570         System.out.println(apple.getName());
 571 
 572         Main myMain=new Main(1970, "Sun");
 573         System.out.println(myMain.modelYear+" "+myMain.modelName);
 574 
 575         Pig myPig_r=new Pig();
 576         myPig_r.animalSound();
 577         myPig_r.sleep();
 578 
 579         Answer myModi=new Answer();
 580         myModi.add();
 581         myModi.delete();
 582         myModi.move();
 583 
 584         People people=new People();
 585         People american=new American();
 586         People chinese=new Chinese();
 587         people.speak_language();
 588         american.speak_language();
 589         chinese.speak_language();
 590 
 591         ArrayList cars=new ArrayList();
 592         cars.add("BMW");
 593         cars.add("Volvo");
 594         cars.add("Mazda");
 595         cars.add("Ford");
 596         cars.add("Toyota")
 597         System.out.println(cars);
 598 
 599         try{
 600             File myFile=new File("filename.txt");
 601             if (myFile.createNewFile()){
 602                 system.out.println("File created: " + myFile.getName());
 603             }else{
 604                 System.out.println("File already exists.");
 605             }
 606         }catch (IOException e) {
 607             System.out.println("An error occurred.");
 608             e.printStackTrace();
 609         }
 610 
 611         try{
 612             FileWriter myWriter = new FileWriter("filename.txt");
 613             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 614             myWriter,close();
 615             System.out.println("Successfully wrote to the file.");
 616         }catch(IOException e) {
 617             System.out.println("An error occurred.");
 618             e.printStackTrace();
 619         }
 620     }
 621 }
 622 import java.util.Scanner; // import the Scanner class
 623 import java.time.LocalDate;// import the LocalDate class
 624 import java.unil.ArrayList;
 625 import java.io.File;
 626 import java.io.IOException;
 627 /* The code is Main Class
 628 */
 629 
 630 abstract class Animal{
 631     //Abstract method
 632     public abstract void animalSound();
 633     //Regular method
 634     public void sleep() {
 635         System.out.println("Zzz");
 636     }
 637 }
 638 
 639 class Pig extends Animal {
 640     public void animalSound(){
 641         System.out.println("The pig says: woo woo");
 642     }
 643 }
 644 
 645 interface Modify {
 646     public void add();
 647     public void delete();
 648     public void move();
 649 }
 650 
 651 class Answer implements Modify {
 652     public void add(){
 653         System.out.println("The answer is that: ");
 654     }
 655     public void delete(){
 656         System.out.println("The answer is: ");
 657     }
 658     public void move(){
 659         System.out.println("The answer is: ");
 660     }
 661 }
 662 
 663 
 664 class People{
 665     public void speak_language(){
 666         system.out.println("The people speak a language");
 667     }
 668 }
 669 
 670 class American extends People{
 671     public void speak_language(){
 672         system.out.println("The American speak English");
 673     }
 674 }
 675 
 676 class Chinese extends People{
 677     public void speak_language(){
 678         system.out.println("The Chinese speak Chinese");
 679     }
 680 }
 681 
 682 
 683  684 public class Fruit{
 685     private String name;
 686 
 687     public String getName(){
 688         return name;
 689     }
 690 
 691     public void setName(String newName){
 692         this.name=newName;
 693     }
 694 }
 695 
 696 public class Main{
 697     int modelYears;
 698     String modelName;
 699 
 700 
 701     public Main(int year, String name) {
 702         modelYears=year; //Set the initial value for the class attribute x
 703         modelName=name;
 704     }
 705 
 706 
 707     enum Level {
 708         LOW,
 709         MEDIUM,
 710         HIGH
 711     }
 712 
 713     public void print_medium(){
 714         Level myVar = Level.MEDIUM;
 715         switch(myVar){
 716         case LOW:
 717             System.out.println("Low Level")
 718             break;
 719         case MEDIUM:
 720             System.out.println("Medium Level")
 721             break;
 722         case HIGH:
 723             System.out.println("HIGH Level")
 724             break;
 725         }
 726     }
 727 
 728     public void scan_info(){
 729         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 730 
 731         System.out.println("Enter name, age and salary:");
 732 
 733         //String input
 734 
 735         String name = myObj.nextline();
 736 
 737         //Numberical input
 738         int age =myObj.nextInt();
 739         double salary = myObj.nextDouble();
 740 
 741         //Output input by user
 742         System.out.println("Name: "+ name);
 743         System.out.println("Age: "+ age);
 744         System.out.println("Salary: "+ salary);
 745 
 746     }
 747 
 748     public void display_formatted_date_time(){
 749         LocalDateTime myDateObj = LocalDateTime.now();
 750         System.out.println("Before formatting: "+myDateObj);
 751         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 752 
 753         String formattedDate=myDateObj.format(myFormatObj);
 754         System.out.println("After formatting: " + formattedDate);
 755     }
 756 
 757 
 758     public static int sum(int k){
 759         if(k>0){
 760             return k+sum(k-1);
 761         }else{
 762             return 0;
 763         }
 764     }
 765 
 766     public static void main(String[] args) {
 767 
 768         int result=sum(10);
 769         System.out.print(result);
 770 
 771         scan_info();
 772         display_formatted_date_time();
 773         print_medium();
 774 
 775         Fruit orange=new Fruit();
 776         orange.setName("Orange");
 777         System.out.println(apple.getName());
 778 
 779         Main myMain=new Main(1970, "Sun");
 780         System.out.println(myMain.modelYear+" "+myMain.modelName);
 781 
 782         Pig myPig_r=new Pig();
 783         myPig_r.animalSound();
 784         myPig_r.sleep();
 785 
 786         Answer myModi=new Answer();
 787         myModi.add();
 788         myModi.delete();
 789         myModi.move();
 790 
 791         People people=new People();
 792         People american=new American();
 793         People chinese=new Chinese();
 794         people.speak_language();
 795         american.speak_language();
 796         chinese.speak_language();
 797 
 798         ArrayList cars=new ArrayList();
 799         cars.add("BMW");
 800         cars.add("Volvo");
 801         cars.add("Mazda");
 802         cars.add("Ford");
 803         cars.add("Toyota")
 804         System.out.println(cars);
 805 
 806         try{
 807             File myFile=new File("filename.txt");
 808             if (myFile.createNewFile()){
 809                 system.out.println("File created: " + myFile.getName());
 810             }else{
 811                 System.out.println("File already exists.");
 812             }
 813         }catch (IOException e) {
 814             System.out.println("An error occurred.");
 815             e.printStackTrace();
 816         }
 817 
 818         try{
 819             FileWriter myWriter = new FileWriter("filename.txt");
 820             myWriter.write("Files in Java might be tricky, but it is fun enough!");
 821             myWriter,close();
 822             System.out.println("Successfully wrote to the file.");
 823         }catch(IOException e) {
 824             System.out.println("An error occurred.");
 825             e.printStackTrace();
 826         }
 827     }
 828 }
 829 import java.util.Scanner; // import the Scanner class
 830 import java.time.LocalDate;// import the LocalDate class
 831 import java.unil.ArrayList;
 832 import java.io.File;
 833 import java.io.IOException;
 834 /* The code is Main Class
 835 */
 836 
 837 abstract class Animal{
 838     //Abstract method
 839     public abstract void animalSound();
 840     //Regular method
 841     public void sleep() {
 842         System.out.println("Zzz");
 843     }
 844 }
 845 
 846 class Pig extends Animal {
 847     public void animalSound(){
 848         System.out.println("The pig says: woo woo");
 849     }
 850 }
 851 
 852 interface Modify {
 853     public void add();
 854     public void delete();
 855     public void move();
 856 }
 857 
 858 class Answer implements Modify {
 859     public void add(){
 860         System.out.println("The answer is that: ");
 861     }
 862     public void delete(){
 863         System.out.println("The answer is: ");
 864     }
 865     public void move(){
 866         System.out.println("The answer is: ");
 867     }
 868 }
 869 
 870 
 871 class People{
 872     public void speak_language(){
 873         system.out.println("The people speak a language");
 874     }
 875 }
 876 
 877 class American extends People{
 878     public void speak_language(){
 879         system.out.println("The American speak English");
 880     }
 881 }
 882 
 883 class Chinese extends People{
 884     public void speak_language(){
 885         system.out.println("The Chinese speak Chinese");
 886     }
 887 }
 888 
 889 
 890  891 public class Fruit{
 892     private String name;
 893 
 894     public String getName(){
 895         return name;
 896     }
 897 
 898     public void setName(String newName){
 899         this.name=newName;
 900     }
 901 }
 902 
 903 public class Main{
 904     int modelYears;
 905     String modelName;
 906 
 907 
 908     public Main(int year, String name) {
 909         modelYears=year; //Set the initial value for the class attribute x
 910         modelName=name;
 911     }
 912 
 913 
 914     enum Level {
 915         LOW,
 916         MEDIUM,
 917         HIGH
 918     }
 919 
 920     public void print_medium(){
 921         Level myVar = Level.MEDIUM;
 922         switch(myVar){
 923         case LOW:
 924             System.out.println("Low Level")
 925             break;
 926         case MEDIUM:
 927             System.out.println("Medium Level")
 928             break;
 929         case HIGH:
 930             System.out.println("HIGH Level")
 931             break;
 932         }
 933     }
 934 
 935     public void scan_info(){
 936         Scanner myObj=new Scanner(System.in); //Create a Scanner object
 937 
 938         System.out.println("Enter name, age and salary:");
 939 
 940         //String input
 941 
 942         String name = myObj.nextline();
 943 
 944         //Numberical input
 945         int age =myObj.nextInt();
 946         double salary = myObj.nextDouble();
 947 
 948         //Output input by user
 949         System.out.println("Name: "+ name);
 950         System.out.println("Age: "+ age);
 951         System.out.println("Salary: "+ salary);
 952 
 953     }
 954 
 955     public void display_formatted_date_time(){
 956         LocalDateTime myDateObj = LocalDateTime.now();
 957         System.out.println("Before formatting: "+myDateObj);
 958         DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
 959 
 960         String formattedDate=myDateObj.format(myFormatObj);
 961         System.out.println("After formatting: " + formattedDate);
 962     }
 963 
 964 
 965     public static int sum(int k){
 966         if(k>0){
 967             return k+sum(k-1);
 968         }else{
 969             return 0;
 970         }
 971     }
 972 
 973     public static void main(String[] args) {
 974 
 975         int result=sum(10);
 976         System.out.print(result);
 977 
 978         scan_info();
 979         display_formatted_date_time();
 980         print_medium();
 981 
 982         Fruit orange=new Fruit();
 983         orange.setName("Orange");
 984         System.out.println(apple.getName());
 985 
 986         Main myMain=new Main(1970, "Sun");
 987         System.out.println(myMain.modelYear+" "+myMain.modelName);
 988 
 989         Pig myPig_r=new Pig();
 990         myPig_r.animalSound();
 991         myPig_r.sleep();
 992 
 993         Answer myModi=new Answer();
 994         myModi.add();
 995         myModi.delete();
 996         myModi.move();
 997 
 998         People people=new People();
 999         People american=new American();
1000         People chinese=new Chinese();
1001         people.speak_language();
1002         american.speak_language();
1003         chinese.speak_language();
1004 
1005         ArrayList cars=new ArrayList();
1006         cars.add("BMW");
1007         cars.add("Volvo");
1008         cars.add("Mazda");
1009         cars.add("Ford");
1010         cars.add("Toyota")
1011         System.out.println(cars);
1012 
1013         try{
1014             File myFile=new File("filename.txt");
1015             if (myFile.createNewFile()){
1016                 system.out.println("File created: " + myFile.getName());
1017             }else{
1018                 System.out.println("File already exists.");
1019             }
1020         }catch (IOException e) {
1021             System.out.println("An error occurred.");
1022             e.printStackTrace();
1023         }
1024 
1025         try{
1026             FileWriter myWriter = new FileWriter("filename.txt");
1027             myWriter.write("Files in Java might be tricky, but it is fun enough!");
1028             myWriter,close();
1029             System.out.println("Successfully wrote to the file.");
1030         }catch(IOException e) {
1031             System.out.println("An error occurred.");
1032             e.printStackTrace();
1033         }
1034     }
1035 }

added moved changed