
// Metoder4.java

/******************************************************************************
/ Metoder4.java utför enkla beräkningar.
/
/ Programmet demonstrerar:
/
/   - Metoder med olika antal inparametrar
/   - Lokala / global variabler
/   - Metod som anropar annan metod
/   - Användning av resultat returnerat från metod
/
/*****************************************************************************/

public class Metoder4
{

	// Global variabel
	static int t2 = -5;

    public static void main(String[] args)
    {	int		t1 = 100;
    	int		t2 = 200;
		int		t3 = 300;

		System.out.println ("Startvärden :");
		System.out.println ("local  t1 = " + t1);
		System.out.println ("local  t2 = " + t2);
		System.out.println ("global t2 = " + Demo4.t2);
		System.out.println ("local  t3 = " + t3);
		System.out.println ();

		// t1 = t1 * 3, global t2 ändras
		t1 = mult3 (t1);
		System.out.println ("Efter anrop till mult3 (t1) :");
		System.out.println ("local  t1 = " + t1 + " <==");
		System.out.println ("local  t2 = " + t2 + " <== !");
		System.out.println ("global t2 = " + Demo4.t2 + "  <== !");
		System.out.println ("local  t3 = " + t3);
		System.out.println ();

		// t1 = t1 * t2, t2 ändras i anropad metod till 5, lokal t2 oförändrad
		t1 = multTal (t1, t2);
		System.out.println ("Efter anrop till multTal (t1, t2) :");
		System.out.println ("local  t1 = " + t1 + " <==");
		System.out.println ("local  t2 = " + t2 + "  <== !");
		System.out.println ("global t2 = " + Demo4.t2);
		System.out.println ("local  t3 = " + t3);
		System.out.println ();

		t3 = divMult (t3);
		System.out.println ("Efter anrop till divMult (t3) :");
		System.out.println ("local  t1 = " + t1);
		System.out.println ("local  t2 = " + t2);
		System.out.println ("global t2 = " + Demo4.t2);
		System.out.println ("local  t3 = " + t3 + " <==");
		System.out.println ();


	}

/******************************************************************************
/ Multiplicerar ett tal med 3 samt ändrar den globala variabeln t2.
/
/ IN : (int) t1 : Tal att multiplicera
/
/ UT : (int)    : t1 multiplicerat med 3
/
/*****************************************************************************/
	public static int mult3(int t1)
	{
		t2 = 10;

		return t1 * 3;
	}

/******************************************************************************
/ Ändrar den ena inparametern och multiplicerar sedan de två parametrarna med
/ varandra.
/
/ IN : (int) t1 : Faktor 1
/      (int) t2 : Faktor 2
/
/ UT : (int)    : t1 multiplicerat med t2
/
/*****************************************************************************/
	public static int multTal(int t1, int t2)
	{
		t2 = 5;

		return t1 * t2;
	}

/******************************************************************************
/ Dividerar ett tal med 2 och multiplicerar sedan kvoten med 3 genom att an-
/ ropa mult3().
/
/ IN : (int) t3 : Talet att dividera och multiplicera
/
/ UT : (int)    : t3 / 2 * 3
/
/*****************************************************************************/
	public static int divMult(int t3)
	{
		int t1 = mult3 (t3 / 2);
		return t1;
	}

}