Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1. ***** PROBLEM 3 ********
  2.  
  3.  
  4. public class BankAccount{
  5.     private String name, address, accountID;
  6.     private double balance;
  7.  
  8.     public String getName(){
  9.         return name;
  10.     }
  11.     public void setName(String name){
  12.         this.name = name;
  13.     }
  14.     public String getAccountID(){
  15.         return accountID;
  16.     }
  17.     public String getAddress(){
  18.         return address;
  19.     }
  20.     public double getBalance(){
  21.         return balance;
  22.     }
  23.     public void setAccountID(String accountID){
  24.         this.accountID = accountID;
  25.     }
  26.     public void setAddress(String address){
  27.         this.address = address;
  28.     }
  29.     public void setBalance(double balance){
  30.         this.balance = balance;
  31.     }
  32.     public void addInterest(){
  33.         balance += ( balance * 7 ) / 100 ;
  34.     }
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. public class Main{
  45.     public static void main(String args[]){
  46.         BankAccount acc1 = new BankAccount();
  47.         BankAccount acc2 = new BankAccount();
  48.         BankAccount acc3 = new BankAccount();
  49.  
  50.         acc1.setName("Jawad");
  51.         acc2.setName("Farhan");
  52.         acc3.setName("Alif");
  53.         acc1.setBalance(100);
  54.         acc1.addInterest();
  55.         System.out.println(acc1.getName());
  56.         System.out.println(acc1.getBalance());
  57.     }
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. ******* PROBLEM 4 **********
  68.  
  69.  
  70. public class Student{
  71.     private String name, id, address;
  72.     private double cgpa;
  73.  
  74.     public String getName(){
  75.         return name;
  76.     }
  77.     public String getID(){
  78.         return id;
  79.     }
  80.     public String getAddress(){
  81.         return address;
  82.     }
  83.     public double getCGPA(){
  84.         return cgpa;
  85.     }
  86.     public void setName(String name){
  87.         this.name = name;
  88.     }
  89.     public void setID(String id){
  90.         this.id = id;
  91.     }
  92.     public void setAddress(String address){
  93.         this.address = address;
  94.     }
  95.     public void setCGPA(double cgpa){
  96.         this.cgpa = cgpa;
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104. public class MainStudent{
  105.     public static void main(String args[]){
  106.         Student[] arr = new Student[10];
  107.         arr[0] = new Student();
  108.         arr[0].setCGPA(3.69);
  109.         arr[0].setName("Habibi");
  110.         System.out.println(arr[0].getName()+" " +arr[0].getCGPA());
  111.     }
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. **** PROBLEM 5 ******
  121.  
  122.  
  123.  
  124.  
  125. public class Triangle{
  126.     private int a, b, c;
  127.  
  128.     public Triangle(){
  129.         a = 0;
  130.         b = 0;
  131.         c = 0;
  132.     }
  133.  
  134.     public void setTriangle(int a, int b, int c){
  135.         this.a = a;
  136.         this.b = b;
  137.         this.c = c;
  138.     }
  139.  
  140.     public boolean isRight(){
  141.         if((b*b)+(a*a)==c*c) return true;
  142.         else if((c*c)+(a*a)==b*b) return true;
  143.         else if((b*b)+(c*c)==a*a) return true;
  144.         return false;
  145.     }
  146.     public boolean isScalene(){
  147.         if(a == b) return false;
  148.         if(a == c) return false;
  149.         if(b == c) return false;
  150.         return true;
  151.     }
  152.     public boolean isIsosceles(){
  153.         if(a==b && a!=c) return true;
  154.         if(a==c && a!=b) return true;
  155.         if(b==c && b!=a) return true;
  156.         return false;
  157.     }
  158.     public boolean isEquilateral(){
  159.         if(a == b && a == c) return true;
  160.         return false;
  161.     }
  162.  
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement