| CCS 2100 | | Comp 310 | | CCS 1300 | | CCS 1200 | | CCS 1100 | | CCS 1000 | | CS 212 | | Email: cpuccs@yahoo.com

Wednesday, November 21, 2012

CCS 1300 Course Outline

CCS 1300: Course Outline

Click HERE
or visit
http://www.2shared.com/document/C1ICLM_O/COURSE_OUTLINE_CCS1300.html

Data Structures and Algorithm: Object Oriented Design: Example 1: Circle

Data Structures and Algorithm: Object Oriented Design: Example 1: Circle

Problem: Create a program that would ask the user for the radius of a circle then display its area and circumference.
CLASS: Circle, TestProgCircle

// Circle.java -------------------------------------------------------------
public class Circle {
private double rad;
private double a;
private double c;

public Circle(){ //default constructor
rad = 0;
}

public Circle(double r){ //constructor with parameters
rad = r;
}

public Circle(Circle other){ //copy constructor
rad = other.rad;
}

public String toString(){
String str;
a = 3.1416 * rad * rad;
c = 3.1416 * 2 * rad;
str = "The area is " + a + " and the circumference is " + c;
return str;
}
}
// end of Circle.java -----------------------------------------------------

// TestProgCircle.java ----------------------------------------------------
import java.io.*;
import java.util.*;

public class TestProgCircle {
public static void main(String [] args) throws IOException{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
double no;

System.out.print("Enter a radius: ");
no = Double.parseDouble(keyboard.readLine());

Circle c1 = new Circle(no);

System.out.println("C1: " + c1);
}
}
// end of TestProgCircle.java ---------------------------------------------

Thursday, September 27, 2012

Data Structures and Algorithm Using Java Sample Program

Data Structures and Algorithm Using Java Sample Program

Click Here or

Here is the link:
http://www.2shared.com/file/zzLAufJu/Sample_Prog.html

Samples of Stacks and Queues are present with the filename Test_Lastname.java

Goodluck with the final exams!

Sunday, July 22, 2012

Address Book using Array-Based Lists

The following is a program that would act as an Address Book using Array-Based Lists:

http://www.2shared.com/file/u6X0pBTZ/AddressBook.html

NOTE: Copy Ch3_Ex8Data.txt in the Drive C:.

Abstract Functions in ArrayClassList

Here is the link for a program that shows how to tap the abstract functions of the ArrayListClass:

http://www.2shared.com/file/-0Si-vsF/Abstract_Func.html

Sunday, July 15, 2012

Array-Based Lists (Chapter 3)

Array-Based Lists
http://www.2shared.com/file/EBAxGx23/ArrayBasedList.html

This program would ask the user for 8 integers. Then, it will ask a position to be deleted and display the smallest number.

Tuesday, July 10, 2012

Inheritance Box

The link for Inheritance Box:

http://www.2shared.com/file/dd7MqR6Z/Inheritance_Box.html

This program would ask the user for the length, width and depth of a box, and calculate its volume. Updated with try/catch block and do while loop

Below is the encoded version of the program.

**************** Rectangle.java *************
public class Rectangle{
protected double length;
protected double width;
protected double area;

public Rectangle(){
length = 0;
width = 0;
}

public Rectangle(double l, double w){
length = l;
width = w;
}

public Rectangle(Rectangle other){
length = other.length;
width = other.width;
}

public String toString(){
String str = " ";
area = length * width;
str = "Area: " + area;
return (str);
}

public void setDimensionRectangle(double l, double w){
if (l < 0) length = 0;
else length = l;
if (w < 0) width = 0;
else width = w;
}
}
**************** end of Rectangle.java ************

***************** Box.java *************
public class Box extends Rectangle{
private double depth;
private double volume;

public Box(){
super(0,0);
depth = 0;
}
public Box(double l, double w, double d){
super(l,w);
depth = d;
}

public Box(Box other){
super(other.length, other.width);
depth = other.depth;
}

public Box(Rectangle r, double d){
super(r.length, r.width);
depth = d;
}

public String toString(){
String str = " ";
volume = length * width * depth;
str = "Volume: " + volume;
return (str);
}

public void setDimensionBox(double l, double w, double d){
setDimensionRectangle(l, w);
if (d < 0) depth = 0; else depth = d; } } ***************** end of Box.java **************

***************** TestProgBox.java **************
import java.io.*;

public class TestProgBox{
public static void main(String[] args) throws IOException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

double length = 0;
double width = 0;
double depth = 0;

Box b1 = new Box();
Box b2 = new Box(3,4,5);
Box b3 = new Box(b2);

Rectangle r4 = new Rectangle(5,7);
Box b4 = new Box(r4,8);

System.out.println("b1: " + b1);
System.out.println("b2: " + b2);
System.out.println("b3: " + b3);

System.out.println("b4: " + b4);


System.out.println("Enter length: ");
length = Double.parseDouble(keyboard.readLine());

System.out.println("Enter width: ");
width = Double.parseDouble(keyboard.readLine());

System.out.println("Enter depth: ");
depth = Double.parseDouble(keyboard.readLine());

b1.setDimensionBox(length, width, depth);
System.out.println("b1: " + b1);

}
}
****************** end of TestProgBox.java *********

************** TestProgBox2.java ***********
import java.io.*;

public class TestProgBox2{
public static void main(String[] args) throws IOException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));

double length = 0;
double width = 0;
double depth = 0;
boolean done = false;

Box b1 = new Box();
do{
try{
System.out.println("Enter length: ");
length = Double.parseDouble(keyboard.readLine());

System.out.println("Enter width: ");
width = Double.parseDouble(keyboard.readLine());

System.out.println("Enter depth: ");
depth = Double.parseDouble(keyboard.readLine());

b1.setDimensionBox(length, width, depth);
System.out.println("b1: " + b1);
done = true;
} catch (NumberFormatException x1){
System.out.println("Input is number, not letters. Try again.");
}
}while(!done);

}
}
************* end of TestProgBox2.java **********