COMPUTER PROGRAMMING 2014 WEEK 2

Notes:

Unicode : www.unicode.org

Tablo 2.2.1 Heksagonal(sixteen base), and 10 base and binary number systems equvalancy

Heksagonal

10 base

2 base (binary)

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

A

10

1010

B

11

1011

C

12

1100

D

13

1101

E

14

1110

F

15

1111

 

Table 2.2.3 Some unicode character tables

 

                     

HOMEWORK PROBLEMS:

PROBLEM 1 : write the following code and run

import javax.swing.*;

public class W2E1

{

public static void main(String arg[])

{ //Calculate d=b*b-4.0*a*c;

String sa=JOptionPane.showInputDialog("a=");

String sb=JOptionPane.showInputDialog("b=");

String sc=JOptionPane.showInputDialog("c=");

double a=Double.parseDouble(sa);

double b=Double.parseDouble(sb);

double c=Double.parseDouble(sc);

//Determinant

double d=b*b-4.0*a*c;

String s="delta="+b+"^2-4*"+a+"*+"+c+" = "+d;

JOptionPane.showMessageDialog(null,s);

}}

 

PROBLEM 2 : write the following code and run

import javax.swing.*;

public class W2E2

{

public static void main(String args[])

{

char b1,b2,b3,b4,b5,b6;

b1='ü';

b2='ğ';

b3='ç';

b4='a';

b5='b';

b6='c';

String s=""+b1+b2+b3+b4+b5+b6;

JOptionPane.showMessageDialog(null,s,"char type",JOptionPane.PLAIN_MESSAGE);

}

}

 

PROBLEM 3 : write the following code and run

public class W2E3

{

public static void main(String args[])

{ //Greek letters

char b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14;

char b15,b16,b17,b18,b19,b20,b21,b22,b23,b24;

String s="Greek Alphabet \n";

b1='\u03B1'; // alfa

b2='\u03B2'; // beta

b3='\u03B3'; // gamma

b4='\u03B4'; // delta

b5='\u03B5'; // epsilon

b6='\u03B6'; // fi

b7='\u03B7'; // eta

b8='\u03B8'; // teta

b9='\u03B9'; // ypsilon

b10='\u03BA'; // kappa

b11='\u03BB'; // lambda

b12='\u03BC'; //

b12='\u03BD'; //

b13='\u03BE'; // ksi

b14='\u03BF'; // o

b15='\u03C0'; // pi

b16='\u03C1'; // ro

b17='\u03C2'; //

b18='\u03C3'; //

b19='\u03C4'; //

b20='\u03C5'; //

b21='\u03C6'; //

b22='\u03C7'; //

b23='\u03C8'; //

b24='\u03C9'; //

s+=""+b1+b2+b3+b4+b5+b6+b7+b8+b9+b10+b11+b12+b13+b14+b15+b16+b17+b18+b19+b20+b21+b22+b23+b24;

JOptionPane.showMessageDialog(null,s,"======Greek Letters======",JOptionPane.PLAIN_MESSAGE);

}

}

 

PROBLEM4 : write the following code and run

import javax.swing.*;

class W2E4

{

public static void main(String args[])

{

char b1,b2;

b1='\u0394'; //Capital delta

b2='\u00B2'; //square(2) sign

String s=""+b1+"T ="+b1+"x"+b2+" + "+b1+"y"+b2;

JOptionPane.showMessageDialog(null,s," character programming",JOptionPane.PLAIN_MESSAGE);

}}

 

PROBLEM5 : write the following code and run

import javax.swing.*;

public class W2E5

{ public static void main(String[] args)

{

boolean b1,b2;

b1=true;

b2=false;

String s="b1 : "+ b1+" b2 : "+b2+"\n";

s+="b1 && b2 "+ (b1&&b2)+"\n";

s+="b1 || b2 "+ (b1||b2)+"\n";

int number1,number2;

number1=1;

number2=2;

s+="number 1 : "+number1+"\n";

s+="number 2 : "+number2+"\n";

b1=(number1 > number2);

s+=number1+" > "+number2+" "+ b1+"\n";

b1=(number1 < number2);

s+=number1+" < "+number2+" "+ b1+"\n";

b1=(number1 == number2);

s+=number1+" == "+number2+" "+ b1+"\n";

b1=(number1 >= number2);

s+=number1+" >= "+number2+" "+ b1+"\n";

b1=(number1 <= number2);

s+=number1+" <= "+number2+" "+ b1+"\n";

b1=(number1 != number2);

s+=number1+" != "+number2+" "+ b1;

JOptionPane.showMessageDialog(null,s);

}

}

 

PROBLEM 6  Write the following code into the editor and run

import java.io.*; //java girdi cikti sinifini cagir

import javax.swing.*;

 

class star

 {    public static void main(String args[])

      {

         final String star = "*";

          String s1=star+"\n";

          String s2="   "+s1;

          String s3="   "+s2;

          String s4="   "+s3;

          String s=s1+s2+s3+s4;

          JOptionPane.showMessageDialog(null,s,"star graphic",JOptionPane.PLAIN_MESSAGE);

     }

 }

 

Now change the program to create the following output: The name of the class and program will be: W2E6

PROBLEM 7  Write the following code into the editor and run

import javax.swing.*;

public class W2E7

{

public static void main(String arg[])

{

double a=2.0;

double y;

if(a<0) {y=2*a;}

else if(a==0) {y=a*a;}

else {y=a*a-3*a;}

String s="y = "+y+" a= "+a;

JOptionPane.showMessageDialog(null,s,"Problem 1",JOptionPane.PLAIN_MESSAGE);

}

}

 

PROBLEM 8  Write the following code into the editor and run

import javax.swing.*;

public class W2E8

{         

public static void main(String arg[])

{

int T=Integer.parseInt(JOptionPane.showInputDialog("Enter Temperature (degree Celcius)"));

String s="";

if(T<10) {s="today is chilly";}

else if(T<15) {s="today is cold";}

else if(T>=15 && T<=25) {s="today is nice";}

else if(T>=25 && T<=30) {s="today is warm";}

else if(T>=30 && T<=40) {s="today is hot";}

else  {s="it is like a hell today";}

s="T = "+T+" degree Celcius wheather condition = "+s;

JOptionPane.showMessageDialog(null,s,"Problem 3",JOptionPane.PLAIN_MESSAGE);

}

}

 

PROBLEM 9 : Write the following code into the editor and run

import javax.swing.*;

public class W2E9

{         

public static void main(String arg[])

{

char gradeletter='A';

int grade=Integer.parseInt(JOptionPane.showInputDialog("Enter the grade number (0-100)"));

if(grade>=85 && grade<=100)

{gradeletter='A';}

else if(grade>=75&&grade<85)

{gradeletter='B';}

else if(grade>=65&&grade<75)

{gradeletter='C';}

else if(grade>=50&&grade<65)

{gradeletter='D';}

else if(grade>=35&&grade<50)

{gradeletter='E';}

else if(grade>=0&&grade<35)

{gradeletter='E';}

else

{gradeletter='N';}

String s="Your number grade = "+grade+" your letter grade = "+gradeletter;

JOptionPane.showMessageDialog(null,s,"Problem 3",JOptionPane.PLAIN_MESSAGE);

}}

 

PROBLEM 10:  Write a program to enter a double variable named x in  graphic screen and write the results of x and y function y defined as:    y(x)=x*x+2*x-5   if x<4  and y(x)=x-2 if y>=4. This type of functions are called partially continious functions. Write the results in   in graphic screen. The name of the program and class will be W2E10

PROBLEM 11:  Enter Two double number from the screen. Compare two numbers and write the results. For example if the numbers you entered 1.23 and 2.34 Write

1.23 < 2.34  true

1.23 > 2.34 false

1.23 == 2.34 false

The name of the program and class will be W2E11

PROBLEM 12:  Select a color (String variable). If color is blue, black, Brown, grey write “you select a cold color”. If color is yellow, green, red write “you select a hot color” if it is not any of these colors write “ I do not know the color you selected”

Note:  string variable comparison will be made by using equals method

String s=”cold”;

String s1=””

if(s.equals(“hot”)) {s1=”xxx”; }

The name of the program and class will be W2E12

PROBLEM 13:  For a student read name, homework grade, midterm examination grade and final grade. Calculate class grade by equation

Class grade = 0.3*homework grade + 0.3*midterm grade+0.4*final grade

if total grade is less than 60 write “you failed”, if it is equal or bigger than 60, write “you passed”

The name of the program and class will be W2E13

Have a happy bayram!