Advertisement
Guest User

asdsad

a guest
Dec 10th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public class CalculatingMachine {
  2. public String string;
  3. public CalculatingMachine(String string){
  4. this.string = string;
  5. }
  6. public String calculate(double x, double y){
  7. double suma = x + y;
  8. return string+": "+x+"+"+y+"="+suma;
  9. }
  10. public static void printRes(CalculatingMachine[] a, double x, double y){
  11. for(int i=0; i<a.length; i++){
  12. System.out.println(a[i].calculate(x,y));
  13. }
  14. }
  15. }
  16. //////////////////////////////////////////////////////////////////////////
  17. public class Computer
  18. extends Calculator {
  19. public Computer(String string){
  20. super(string);
  21. }
  22. public String calculate(double x, double y){
  23. double iloczyn = x*y, iloraz = x/y;
  24. return super.calculate(x,y)+"; "+x+"*"+y+"="+iloczyn+"; "+x+"/"+y+"="+iloraz;
  25. }
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. public class Calculator
  29. extends CalculatingMachine {
  30. public Calculator(String string){
  31. super(string);
  32. }
  33. public String calculate(double x, double y){
  34. double roznica = x-y ;
  35. return super.calculate(x,y)+"; "+x+"-"+y+"="+roznica;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement