Advertisement
airton-junior

Boletim (Getters & Setters) e Construtor

Apr 20th, 2023
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public class Boletim {
  2.     private Decimal n1;
  3.     private Decimal n2;
  4.     private Decimal n3;
  5.     private Decimal n4;
  6.     private Decimal media;
  7.    
  8.     public Boletim(){
  9.        
  10.     }
  11.     public Boletim(Decimal n1, Decimal n2, Decimal n3, Decimal n4){
  12.         this.n1 = n1;
  13.         this.n2 = n2;
  14.         this.n3 = n3;
  15.         this.n4 = n4;
  16.  
  17.     }
  18.     public void setN1(Decimal n1){
  19.         this.n1 = n1;
  20.     }
  21.     public void setN2(Decimal n2){
  22.         this.n2 = n2;
  23.     }
  24.     public void setN3(Decimal n3){
  25.         this.n3 = n3;
  26.     }
  27.     public void setN4(Decimal n4){
  28.         this.n4 = n4;
  29.     }
  30.     public Decimal getMedia(){
  31.         return this.media;
  32.     }
  33.     public String calculaMedia(){
  34.         this.media = (n1+n2+n3+n4)/4;
  35.         if(this.media>=5){
  36.             if(this.media>10){
  37.                 return 'Nota incorreta';
  38.             }
  39.             return 'Aprovado';
  40.         }else if(media>=4){
  41.             return 'Recuperação';
  42.         }else{
  43.             return 'Reprovado';
  44.         }
  45.     }
  46. }
  47.  
  48. //ANONYMOUS
  49. /*Boletim b = new Boletim();
  50. b.setN1(5);
  51. b.setN2(8);
  52. b.setN3(3);
  53. b.setN4(10);
  54. System.debug(b.calculaMedia()+' - '+b.getMedia());*/
  55.  
  56. /*Boletim b = new Boletim(5, 8, 3, 10);
  57. System.debug(b.calculaMedia()+' - '+b.getMedia());*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement