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