Static methods is used so it cud be used from other classes without making a new object out of the class it self. So let say you have a static vale of 10, and you want to share it with the other class, you simply call the class name and then the method that returns its value, like this: className.methodName();
now this task is done with two classes, it will generate random arrays that holds 12 arrays, and will put in randomized order {u,h,b) shortcut in norwegian as uavgjort, borte, hjem.
import java.util.Scanner;
public class Tipping
{
static Scanner input = new Scanner(System.in);
private static int feil = 0;
private static int antall = 0;
private static char dinGjett = 0;
static char[] tegnene = new char[ 12 ];
private static char[] dinTegn = new char[ tegnene.length];
private static char[] str = new char[] {'H','U','B'};
public static char tippingEnkeltRekke(char[] tegnene)
{
for( int i = 0; i < tegnene.length; i++ )
{
tegnene[i] += str[(char)(Math.random () * str.length)]; // Generate and place it random back to the list...
}
return 0;
}
public static char Min()
{
for(int i = 0; i < dinTegn.length; i++)
{
System.out.print("Din Gjett ( " + i + " ) Skriv din liste 12 Gjett FORVENTET: " );
String gjett = input.next();
dinGjett = gjett.charAt(0);
dinTegn[i] += dinGjett;
}
return 0;
}
public static int sjekkGevinst()
{
for(int i = 0; i < tegnene.length; i++)
{
if(tegnene[i] == dinTegn[i])
{
antall++;
} else
feil++;
}
return 0;
}
public static void skrivTipperekke()
{
for( int i = 0; i < 12; i++)
{
System.out.printf("\n%c%15c", tegnene[i], dinTegn[i]); // Print out all char list...
}
System.out.println("\nAntall Riktig Match: " + antall + "\nAntall Feil: " + feil);
}
}// end of Tipping class.
Now the second class witch runs the program-
public class TippingManager
{
public static void main(String[] args)
{
Tipping.tippingEnkeltRekke(Tipping.tegnene); // Generate the list random...
Tipping.Min();
Tipping.sjekkGevinst();
Tipping.skrivTipperekke(); // SKriv ut alle TippeRekkene...
}
}