File Location Link: CCC 101N: Computer Programming 1 Laboratory Activity: Programming Basics & Methods
File Location Link: CCC 101N: Computer Programming 1 Laboratory Activity: Programming Basics & Methods
File Location Link: CCC 101N: Computer Programming 1 Laboratory Activity: Programming Basics & Methods
GUIDANCE:
File location
Place all your programs in the Desktop folder for easy access.
Link
Link the Java compiler to the directory where your programs reside. In our case the programs are in the
Desktop folder.
a. Open Command Prompt.
b. Navigate to the directory where your programs are placed. In our case we key this DOS command
through the keyboard in the Command Prompt
cd Desktop
c. Key this through the keyboard to link the java compiler to the directory
(Important notes: The JDK’s folder name depends on the JDK version. In our case it is “jdk1.7.0_45”. If you
are using a 32 bit version of JDK, it is located in “Program Files (x86)”.)
Compile
To compile the program, key this command in the Command Prompt
javac NameOfOurProgram.java
To use this class, import the library to your program by keying this
import java.util.Scanner;
(Important note: You can change the identifier “nameOfScanner” name to your preferred name.)
Just search for the complete list of Scanner input methods in the Internet.
/**
* @file Name of the Program (.java)
* @description Provide a description of the program/file
* (what is this file supposed to do)
* @course CCC 101 Section W
* @lab Lab Activity 2
* @date 09/11/2018
* @author YOUR SURNAME, Your First Name
*/
import java.util.Scanner;
NOTE: For lab activity 2.1, try running the program, play with the source code and observe its behavior.
Laboratory Activity 2.1 Encode and run this program. Save this program as “TestProgram.java”.
import java.util.Scanner;
Write a method and name it as addBinary. This method takes two integer parameters, say num1 and num2, and
returns the sum of the two binary numbers.
Write the complete program to test your method. Name your program as BinaryAdditionProgram. Your program
should look like the Sample Dialogs below. Don’t forget to include the header part.
Sample Dialog 1:
Sample Dialog 2:
Write a method and name it as subtractBinary. This method takes two integer parameters, say num1 and num2,
and returns the difference of the two binary numbers. Note that for this program, the first number should be greater
than the second number.
Write the complete program to test your method. Name your program as BinarySubtractionProgram. Your
program should look like the Sample Dialogs below. Don’t forget to include the header part.
Sample Dialog 1:
Sample Dialog 2:
Note: Please TURN IN your programs. DO NOT post NOR send them as a private message. In addition, don’t forget to
write the header part of your Laboratory Activity 2.1’s code. Apply this in the other Lab Activities as well.