These two codes are part of the case study of the polynomials 1- explain in detail how to extract the information from the case study and how the code is written. 2- extract the variable. 3- extract the methods from the case study and write the related code. import java.io.*; import java.util.*; public class Variable implements Comparable, Cloneable { public char id; public int exp; public Variable() { } public Variable(char c, int i) { id = c; exp = i; } public int compareTo(Object v) { return id - ((Variable)v).id; } public boolean equals(Object v) { return id == ((Variable)v).id && exp == ((Variable)v).exp; } public Object clone() { return new Variable(id,exp); } } public class Term implements Comparable, Cloneable { public Term() { } public int coeff; public ArrayList vars = new ArrayList(); public Object clone() { Term t = new Term(); t.coeff = coeff; t.vars = (ArrayList) vars.clone(); for (int i = 0; i < vars.size(); i++) t.vars.set(i,((Variable)vars.get(i)).clone()); return t; } public boolean equals(Object term) { int i; for (i = 0; i < Math.min(vars.size(),((Term)term).vars.size()) && vars.get(i).equals(((Term)term).vars.get(i)); i++); return i == vars.size() && vars.size() == ((Term)term).vars.size(); } public int compareTo(Object term2) { if (vars.size() == 0) return 1; // this is just a coefficient; else if (((Term)term2).vars.size() == 0) return -1; // term2 is just a coefficient; Variable var1, var2; for (int i = 0; i < Math.min(vars.size(),((Term)term2).vars.size()); i++) { var1 = (Variable)vars.get(i); var2 = (Variable)((Term)term2).vars.get(i); if (var1.id < var2.id) return -1; // this precedes term2; else if (var2.id < var1.id) return 1; // term2 precedes this; else if (var1.exp < var2.exp) return -1; // this precedes term2; else if (var2.exp < var1.exp) return 1; // term2 precedes this; } return vars.size() - ((Term)term2).vars.size(); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

These two codes are part of the case study of the polynomials

1- explain in detail how to extract the information from the case study and how the code is written.

2- extract the variable.

3- extract the methods from the case study and write the related code.

import java.io.*;
import java.util.*;

public class Variable implements Comparable, Cloneable {
public char id;
public int exp;
public Variable() {
}
public Variable(char c, int i) {
id = c; exp = i;
}
public int compareTo(Object v) {
return id - ((Variable)v).id;
}
public boolean equals(Object v) {
return id == ((Variable)v).id && exp == ((Variable)v).exp;
}
public Object clone() {
return new Variable(id,exp);
}
}

public class Term implements Comparable, Cloneable
{
public Term() {
}
public int coeff;
public ArrayList vars = new ArrayList();
public Object clone() {
Term t = new Term();
t.coeff = coeff;
t.vars = (ArrayList) vars.clone();
for (int i = 0; i < vars.size(); i++)
t.vars.set(i,((Variable)vars.get(i)).clone());
return t;
}
public boolean equals(Object term) {
int i;
for (i = 0; i < Math.min(vars.size(),((Term)term).vars.size()) &&
vars.get(i).equals(((Term)term).vars.get(i)); i++);
return i == vars.size() && vars.size() == ((Term)term).vars.size();
}
public int compareTo(Object term2) {
if (vars.size() == 0)
return 1; // this is just a coefficient;
else if (((Term)term2).vars.size() == 0)
return -1; // term2 is just a coefficient;
Variable var1, var2;
for (int i = 0; i < Math.min(vars.size(),((Term)term2).vars.size()); i++) {
var1 = (Variable)vars.get(i);
var2 = (Variable)((Term)term2).vars.get(i);
if (var1.id < var2.id)
return -1; // this precedes term2;
else if (var2.id < var1.id)
return 1; // term2 precedes this;
else if (var1.exp < var2.exp)
return -1; // this precedes term2;
else if (var2.exp < var1.exp)
return 1; // term2 precedes this;
}
return vars.size() - ((Term)term2).vars.size();
}
}

 

Expert Solution
steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education