Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package Control.Control4;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. class Function{
  7.     double eval(double x){
  8.         if (s == "square"){
  9.             double ev = a*(x*x)+b*x+c;
  10.             return ev;
  11.         }
  12.         else {
  13.             double ev = Math.log(x)/Math.log(a);
  14.             return ev;
  15.         }
  16.     }
  17.  
  18.     String show(){
  19.         if (s == "square"){
  20.             String l = "(" + a + ")*x^2+(" + b + ")*x+(" + c + ")";
  21.             return l;
  22.         }
  23.         else {
  24.             String l = "log_" + a + "_(x)";
  25.             return l;
  26.         }
  27.     }
  28.  
  29.     private int a;
  30.     private int b;
  31.     private int c;
  32.     private String s;
  33.  
  34.     public Function(int a, int b, int c, String s){
  35.         this.a = a;
  36.         this.b = b;
  37.         this.c = c;
  38.         this.s = s;
  39.     }
  40. }
  41.  
  42. class Square extends Function{
  43.     public Square(int a, int b, int c){
  44.         super(a, b, c, "square");
  45.     }
  46. }
  47.  
  48. class Log extends Function{
  49.     public Log(int a){
  50.         super(a, 0, 0, "log");
  51.     }
  52. }
  53.  
  54. public class Ex_1 {
  55.     public static void main(String[] args){
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement