CSE 214 Computer Science II (Spring 2015)

Recitation 1: Java Overview

Objective:

  1. To write, compile and execute a Java program using the Sun JDK or a Java IDE.
  2. Use of arithmetic expressions to accomplish a task
  3. Carry out some simple computation checks on numbers

 

Program #1 [5 min]: Write a program to print “Welcome to java recitation !!!!”

1. Create a new file in your IDE or text editor.

2. Create the shell for your first program by entering:

public class First

{

public static void main(String[] args)

{

// add statement to print here

}

}

3. Save the file as First.java

5. Compile the program and debug, repeating until it compiles successfully.

6. Execute the code

Program #2 [20 min]: Write a program to carry out the following arithmetic computation

  1. Convert a temperature in Fahrenheit scale to Celsius scale
  • C=59 (F - 32)
    1. Compute volume of a sphere
  • V=43 π r3
  • Program #3 [25 min]: Write methods with the following signature:

    [Note: You can make your program more interactive using switch-case]

    1. public static boolean isPrime(int n)

    This method takes a positive integer and returns true if that number is prime and false otherwise, where a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.

    Ex. 2,3, 5, 7 etc.

    1. public static boolean isPerfect(int n)
      This method takes a positive integer and returns true if that number is perfect and false otherwise, where a perfect number is a number that equals the sum of its proper divisors. 

     Ex. 6, 28, 496 etc.

    1. public static boolean isPallindromic(int n)
      This method takes a positive integer and returns true if that number is palindromic and false otherwise, where a palindromic number or numeral palindrome is a number that remains the same when its digits are reversed

    Ex. 131, 1111, 16461 etc.