Lab 3
Lab 3
Dipen Patel
CSC 236
Lab-3A
*/
}
/*
Dipen Patel
CSC 236
Lab-3A
*/
//Default Constructor.
public PolyNode()
info=0;
info2=0;
link=null;
//OverLoaded Constructor.
public PolyNode(PolyNode p)
this.info=p.info;
this.info2=p.info2;
this.link=p.link;
//OverLoaded Constructor
info=c;
info2=e;
link=null;
//OverLoaded Constructor
info=c;
info2=e;
link=next;
info=c;
return info;
info2=e;
link= n;
return link;
}
/*
Dipen Patel
CSC 236
Lab-3A
*/
import java.util.Random;
PolyNode headPointer;
//Default constructor
public PolynomialDataStructure(){
//OVERLOADED CONSTRUCTOR
this.headPointer=p.headPointer;
//OVERLOADED CONSTRUCTOR
if(headPointer.getCoefficient()==0&&headPointer.getExponent()==0)
return true;
else
return false;
headPointer = p;
return headPointer;
if(isEmpty())
else
if(isEmpty())
else{
while(current.getNext()!=null)
current=current.getNext();
current.setNext(new PolyNode(c, e, null));
int higestDegree=0;
PolyNode current = p;
higestDegree=current.getExponent();
while(current.getNext()!=null){
if(current.getExponent()>higestDegree)
higestDegree=current.getExponent();
current=current.getNext();
if(current.getExponent()>higestDegree)
higestDegree=current.getExponent();
return higestDegree;
PolyNode current2= a;
PolyNode temp2=current2;
PolyNode temp=newNode;
while(current!=null)
while(temp2!=null)
if(current.getExponent()==temp2.getExponent()){
temp.setNext(new PolyNode(current.getCoefficient()
+temp2.getCoefficient(),current.getExponent(),null));
current.setExponent(rnd.nextInt(1000)+1000);
temp2.setExponent(rnd.nextInt(1000)+1000);
temp=temp.getNext();
temp2=temp2.getNext();
if(current.getExponent()<100){
temp.setNext(new PolyNode(current.getCoefficient()
, current.getExponent()));
temp=temp.getNext();
current.setExponent(rnd.nextInt(1000)+1000);
temp2=current2;
current=current.getNext();
}
temp2=current2;
current = headPointer;
while(temp2!=null){
while(current!=null){
if(temp2.getExponent()==current.getExponent()){
temp.setNext(new PolyNode(temp2.getCoefficient()
+current.getCoefficient()
,temp2.getExponent(),null));
temp2.setExponent(rnd.nextInt(1000)+1000);
temp=temp.getNext();
current=current.getNext();
if(temp2.getExponent()<10){
temp.setNext(new PolyNode(temp2.getCoefficient()
, temp2.getExponent()));
temp=temp.getNext();
temp2.setExponent(rnd.nextInt(1000)+1000);
temp2=temp2.getNext();
current=headPointer;
headPointer=newNode.getNext();
return "Empty";
else{
String s = "";
while(current!=null){
s=s+(current.getCoefficient()+"x^"+current.getExponent()+"+");
current = current.getNext();
return s;
}
/*
Dipen Patel
CSC 236
Lab-3A
*/
*/
obj1.addPolyNodeLast(3, 2);
obj1.addPolyNodeLast(-5, 0);
obj2.addPolyNodeLast(4, 4);
obj2.addPolyNodeLast(1, 3);
obj2.addPolyNodeLast(-4, 2);
obj2.addPolyNodeLast(4, 1);
obj2.addPolyNodeLast(2, 0);
obj3.addPolyNodeLast(3, 2);
obj3.addPolyNodeLast(4, 3);
obj4.addPolyNodeLast(4, 3);
obj4.addPolyNodeLast(5, 4);
/*
* PRINTS OUT ALL THE CREATED OBJECTS.
*/
/*
*/
obj1.addPolynomial(obj2.getFirstNode());
obj3.addPolynomial(obj4.getFirstNode());
}
/*
Dipen Patel
CSC 236
Lab-3B
*/
}
/*
Dipen Patel
CSC 236
Lab-3B
*/
import java.util.NoSuchElementException;
//Pirvate Variables.
private Student[] s;
//Inner Class.
// Private variables
//Default constructor.
public Student()
studentID = 0;
//Overloaded constructor.
public Student(int studentsId)
studentID = studentsId;
studentID = ID;
course = c;
return course;
//GETS THE ID
return studentID;
if(this.getCourses() == null)
course = new Course(couseadded.getCourseName(),
couseadded.getSectionNumber(),
couseadded.getCredits(), null);
else
Course c = this.course;
while(c.getLink() != null)
c = c.getLink();
c.setLink(new Course(couseadded.getCourseName(),
couseadded.getSectionNumber(),
couseadded.getCredits(), null));
if(isEmpty())
this.course = course.getLink();
droppedCourse = true;
prev = current;
current = current.getLink();
current.getCourseName().equals(dropC.getCourseName())
current = null;
prev.setLink(current);
droppedCourse = true;
else if(current.getCourseName().equals(dropC.getCourseName())
prev.setLink(current.getLink());
current = null;
droppedCourse = true;
if(droppedCourse)
System.out.println("Course has been dropped.");
else
return droppedCourse;
String s = "";
Course c = course;
if(this.isEmpty())
else
while(c != null)
s += c;
c = c.getLink();
return (s);
}
}
//DEFAULT CONSTRUCTOR.
public Students()
this.maxNumOfStudents = 5;
this.currentNumOfStudents = 0;
s = new Student[maxNumOfStudents];
//OVERLOADED CONSTRUCTOR
this.currentNumOfStudents = 0;
this.maxNumOfStudents = max;
s = new Student[max];
//OVERLOADED CONSTRUCTOR.
this.currentNumOfStudents = cStud.currentNumOfStudents;
this.maxNumOfStudents = cStud.maxNumOfStudents;
s = cStud.s;
this.maxNumOfStudents = max;
}
//ADD THE STUDENTS.
currentNumOfStudents++;
if(s[i].getID() == studentsId)
s[i].addCourse(addedcourse);
if(s[i].getID() == studentid)
s[i].dropCourse(droppedcourse);
numStuds += "\n";
return numStuds;
}
/*
Dipen Patel
CSC 236
Lab-3B
*/
/*
*/
//Default Contructor
public Course()
courseName = "";
courseSec = 0;
credit = 0;
link = null;
//Overloaded Constructor.
public Course(String course, int sectionNum, int credits, Course link)
this.courseName = course;
this.courseSec = sectionNum;
this.credit = credits;
this.link = link;
//OverLoaded Constructor.
public Course(Course c)
this.courseName = c.courseName;
this.courseSec = c.courseSec;
this.credit = c.credit;
this.link = c.link;
this.courseName = courseName;
courseSec = coursesec;
credit = coursecredit;
this.link = link;
return courseName;
return courseSec;
return credit;
return link;
}
return outputString;
}
/*
Dipen Patel
CSC 236
Lab-3B
*/
import java.util.*;
/*
*/
int section = 0;
int credit = 0;
int studentID = 0;
int options = 0;
s.addStudent(1111);
s.addStudent(1234);
s.addStudent(2357);
*/
while (options != 9)
System.out.println("9: Quite");
options = scn.nextInt();
if (options == 1) {
System.out.println(s.toString());
else if (options == 2) {
System.out.println("Add a Course");
studentID = scn.nextInt();
scn.nextLine();
section = scn.nextInt();
credit = scn.nextInt();
credit = 4;
if (courseName == "HIS101")
credit = 3;
s.addCourse(studentID, c);
System.out.println(s.toString());
else if (options == 3) {
System.out.println("Drop a course");
studentID = scn.nextInt();
scn.nextLine();
courseName = scn.nextLine();
if ((courseName == "CSC162") || (courseName == "CSC236"))
credit = 4;
if (courseName == "HIS101")
credit = 3;
s.dropCourse(studentID, sDrop);
} else if (options == 9 ) {
System.exit(1);
System.out.println("Thank you.");
scn.close();