## DTCP2023 - FUNDAMENTALS OF PROGRAMMING

Course Outline

Slide Chapter 1 Complex Control Structure

Slide Chapter 2 Java Method

Example Method 1 – Min, Max, Average of 3 numbers

```//********************************************************************
//  Demonstrates the use of methods in Java.
//********************************************************************

import java.util.Scanner;

public class MinOfThree
{
//-----------------------------------------------------------------
//  Reads three integers from the user and determines the smallest
//  value.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int num1, num2, num3, min = 0, max=0;
float average;

Scanner scan = new Scanner (System.in);

displayinfo();

System.out.println ("Enter three integers: ");
num1 = scan.nextInt();
num2 = scan.nextInt();
num3 = scan.nextInt();

//min=minimum(num1, num2, num3);
System.out.println ("Minimum value: " + minimum(num1, num2, num3));

//call maximum method
max=maximum(num1, num2, num3);
System.out.println ("Maximum value: " + max);

//call average method
findaverage(num1, num2, num3);

}//end main

public void findaverage(int num1, int num2, int num3){
float average=(num1+num2+num3)/3;
System.out.println ("Average value: " + average);
}//findaverage

public static void  displayinfo(){
System.out.println ("************************************");
System.out.println ("A Program to find min and max number");
System.out.println ("Author: Kerul.net");
System.out.println ("************************************");
}//end displayinfo

public static int minimum(int num1, int num2, int num3){
int min;
if (num1 < num2){
if (num1 < num3)
min = num1;
else
min = num3;
}
else{
if (num2 < num3)
min = num2;
else
min = num3;
}
return min;

}//end minimum

public static int maximum(int num1, int num2, int num3){
int max;
if (num1 > num2)
if (num1 > num3)
max = num1;
else
max = num3;
else
if (num2 > num3)
max = num2;
else
max = num3;
return max;
}

}//end class```

Example Method 2 – Grade Method

```import java.util.Scanner;

{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
float score = scan.nextInt();

}//end main

//Call the printGrade method from main
public static void printGrade(double score) {
if (score >= 90.0)
System.out.println("A");
else if (score >= 80.0)
System.out.println("B");
else if (score >= 70.0)
System.out.println("C");
else if (score >= 60.0)
System.out.println("D");
else
System.out.println("F");
}//end class```

Slide Chapter 3 Arrays in Java

Sample 1:

public class AverageArray {

public static void main(String[] args) {
//int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
//int[] num = new int;
int num[]={23,34,13,12,32,10,11,31,45,67};
/*num=23;
num=34;
num=13;
num=12;
num=32;*/
float total=0,average;
//float average=(num1+num2+num3+num4+num5+num6+num7+num8+num9+num10)10;
for (int i=0; i<10;i++){
total=total+num[i];
}

average=total/10;
System.out.println("Total="+total);
System.out.println("Average="+average);

//Exercise: List all values that bigger than the average
for (int i=0; i<10;i++){
if (num[i]>average){
System.out.println(num[i]+" is bigger than average");
}
}

}//end main

}

Exercise 1: Get 15 numbers from user, and store the values inside an array variable. Evaluate the biggest and smallest number among the values.

Slide Chapter 4 Class in Java

Slide Chapter 5 File IO in Java

## Found this website and has a easy, simple Java Tutorial, thanks to the author.

Install Java The first step to programming Java is to get it running on your computer. This easy-to-follow guide will show you how to set up Java and Eclipse, complete with screenshots to help you follow along.

Your First Program Got Java and Eclipse installed? Let's make sure everything is set up properly and begin your introduction to Java by starting you with coding your very first program!

Java Output Learn how to easily get Java to display text on the screen. It'll be your proof that you can make a computer do what YOU want it to do!

Java Variables Without variables, there's no way to store values in your program. Learn the basics about creating and using Java's variables so your programs can do more than just display stuff on the screen.

Java Input Want to make your programs interactive? Learning to get input from a user is crucial if your program will ever be used by a human. Java has an easy way of doing this, and that's by using a Java Scanner.

Conditionals ( The If Statement ) Your program is doomed to do exact same thing every time it runs unless you let it know about different conditions. Learn the power of if statements and how to use them to produce different results based on what you tell the code to do.

Loops - For Loops And While Loops If you've been trying out your own programs, you must be getting fed up with having to copy and paste code you want done over and over again. But, there is a better way! Read on to learn how you can make a program do something over and over without having to write it over and over.

Intro To Java Methods The final tutorial in Java For Beginners! Learn a little bit about what Java methods are, how to write them, and how to use them. This tutorial won't cover everything, but it'll be just enough to get you to use them and serves as a jump-off point to the more advanced tutorials.

The tools