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

Wednesday, December 19, 2012

Review: Switch Case Java Samples


This is a simple example of how Switch Case statements in Java work:

-----------------------------SwitchCase.java-----------------------------

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

public class SwitchCase {
public static void main(String [] args) throws IOException{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
int x = 2;
switch(x){
case 1:
System.out.println("x is 1!");
break;
case 2:
System.out.println("x is 2!");
                  System.out.println("Hello!");
                  break;
case 3:
System.out.println("x is 3!");
break;
default:
          System.out.println("x is invalid!");
break;
} // switch closes
}
}


-----------------------------end of SwitchCase.java-----------------------------

Problem: Create a program that would ask the user for the following options:
1: to add
2: to multiply
3: to deduct
Then ask the user for two numbers and display the answer based on the operation chosen.

----------------------Calc.java----------------------------

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

public class Calc {
public static void main(String [] args) throws IOException{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
int option, first, second, answer;

System.out.print("1: to add \n2: to multiply \n3: to deduct \nEnter option: ");
option = Integer.parseInt(keyboard.readLine());
System.out.print("Enter first number: ");
first = Integer.parseInt(keyboard.readLine());
System.out.print("Enter second number: ");
second = Integer.parseInt(keyboard.readLine());

switch(option){
case 1: answer = first + second; break;
case 2: answer = first * second; break;
case 3: answer = first - second; break;
default: System.out.print("Invalid"); answer = 0; break;
}

System.out.println("Answer: " + answer);
}
}


----------------------end of Calc.java----------------------------


------------------------Options.java ----------------------------------



import java.io.*; import java.util.*;
public class Options {
public static void main(String [] args) throws IOException{
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
int option;
System.out.print("Enter option: ");
option = Integer.parseInt(keyboard.readLine());

switch(option){
case 1:
for(int i = 1; i <= 10; i++) { System.out.print(i + " ");}
break;
case 2:
int sum, no1, no2;
System.out.print("Enter first number: ");
no1 = Integer.parseInt(keyboard.readLine());
System.out.print("Enter second number: ");
no2 = Integer.parseInt(keyboard.readLine());
sum = no1 + no2;
System.out.print("The sum is " + sum);
break;
case 3:
int no, rem;
System.out.print("Enter number: ");
no = Integer.parseInt(keyboard.readLine());
rem = no % 2;
if(rem == 1) System.out.print("Odd.");
else System.out.print("Even");
break;
default:
System.out.print("Invalid option");
break;
}

}

}


------------------------end of Options.java ----------------------------------

Monday, December 10, 2012

Research Assignment for CCS 1300

Research Assignment for CCS 1300

Define, identify the functions and methods(and their purpose), and give concrete examples (both in real life and in programming) of the basic types of data structures:

1.     Array – Based Lists
2.     Linked – Lists
3.     Recursion
4.     Stacks
5.     Queues

Pass with your full name, subject description, stub code and lecture schedule at the top of the document.

Format: Short Bond Paper
            Margins: 1” in 4 corners
            Font: Arial
            Size: 11

Deadline: for soft copies, email to cpuccs@yahoo.com with the subject “1300 Research” until January 3, 2013. If the subject is incorrect, your email will be ignored.

For hard copies, pass your work on or before January 8, 2013. Late papers will not be accepted and would automatically merit a score of ZERO. No need to place in a folder but keep the papers neat and stapled properly.

Note: Plagiarism would not merit any score. Although noting references is allowed, copy/paste method is NOT.

- Sir Rod.


Monday, December 3, 2012

Presentations for Chapter 1 and 2

The following are the download links for Chapter 1 and 2 of out CCS 1300 Data Structures and Algorithm classes.

Chapter 1:
http://www.2shared.com/document/wFrd5n4D/chap01.html

Chapter 2:
http://www.2shared.com/document/lihquBR0/chap02.html

P.S. Note that the download button would be the smaller one at the bottom, not the one in the ads.

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

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 **********

Friday, June 29, 2012

Course Outlines

The following are the download links for the give courses.

CCS 1000: Computer Fundamentals
http://www.2shared.com/file/CtTFZ7O8/CCS_1000.html

CCS 1100: Foundations of C Programming
http://www.2shared.com/file/LFXXoHDt/CCS_1100.html

CS 212: Data Structures and Algorithm Using Java
http://www.2shared.com/file/OGgUhISH/CS_212.html