hanonymouss
Gebruiker
- Lid geworden
- 7 sep 2011
- Berichten
- 283
Hallo iedereen
Ik heb een tijd klasse aangemaakt waarbij de gebruiker de tijd moet ingeven in seconden.
Klasse Tijd:
[CPP]/**
* Created with IntelliJ IDEA.
* User: Hanonymouss
* Date: 8/02/13
* Time: 16:39
* To change this template use File | Settings | File Templates.
*/
public class Tijd {
private boolean isSpelGedaan;
private int begintijd;
public Tijd(int begintijd){
this.begintijd = begintijd;
}
public void spelGedaan(){
long start = System.currentTimeMillis();
if(System.currentTimeMillis() - start >= this.begintijd *1000)
this.isSpelGedaan = true;
}
public boolean isSpelGedaan() {
return this.isSpelGedaan;
}
}
[/CPP]
en gebruik hem zo:
[CPP]import java.util.ArrayList;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* User: Hanonymouss
* Date: 7/02/13
* Time: 23:22
* To change this template use File | Settings | File Templates.
*/
public class test {
private static ArrayList<String> list = new ArrayList<String>();
public static void main(String[] args) {
Tijd spel = new Tijd(10);
Scanner scan = new Scanner(System.in);
while (spel.isSpelGedaan() == false) {// werkt ook ni als ik ! voor spel.isSpelGedaan voorzett dus while (!spel.isSpelGedaan() == false)
System.out.println("geef een woord");
String w = scan.nextLine();
list.add(w);
spel.spelGedaan();
// Stop loop
}
for(String w: list){
System.out.println(w);
}
System.out.println("gedaan");
}
}[/CPP]
Ik geraak er nier uit. en met een do while is het probleem tegenovergestelde
dus na 1 gegeven woord sluit hij ineens de appliactie
[CPP] do {
System.out.println("geef een woord");
String w = scan.nextLine();
list.add(w);
spel.spelGedaan();
} while (!spel.isSpelGedaan() == false);
for(String w: list){
System.out.println(w);
}
System.out.println("gedaan");
[/CPP]
graag jullie hulp, mag ook een andere oplosiing zijn
Ik heb een tijd klasse aangemaakt waarbij de gebruiker de tijd moet ingeven in seconden.
Klasse Tijd:
[CPP]/**
* Created with IntelliJ IDEA.
* User: Hanonymouss
* Date: 8/02/13
* Time: 16:39
* To change this template use File | Settings | File Templates.
*/
public class Tijd {
private boolean isSpelGedaan;
private int begintijd;
public Tijd(int begintijd){
this.begintijd = begintijd;
}
public void spelGedaan(){
long start = System.currentTimeMillis();
if(System.currentTimeMillis() - start >= this.begintijd *1000)
this.isSpelGedaan = true;
}
public boolean isSpelGedaan() {
return this.isSpelGedaan;
}
}
[/CPP]
en gebruik hem zo:
[CPP]import java.util.ArrayList;
import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* User: Hanonymouss
* Date: 7/02/13
* Time: 23:22
* To change this template use File | Settings | File Templates.
*/
public class test {
private static ArrayList<String> list = new ArrayList<String>();
public static void main(String[] args) {
Tijd spel = new Tijd(10);
Scanner scan = new Scanner(System.in);
while (spel.isSpelGedaan() == false) {// werkt ook ni als ik ! voor spel.isSpelGedaan voorzett dus while (!spel.isSpelGedaan() == false)
System.out.println("geef een woord");
String w = scan.nextLine();
list.add(w);
spel.spelGedaan();
// Stop loop
}
for(String w: list){
System.out.println(w);
}
System.out.println("gedaan");
}
}[/CPP]
Ik geraak er nier uit. en met een do while is het probleem tegenovergestelde
dus na 1 gegeven woord sluit hij ineens de appliactie
[CPP] do {
System.out.println("geef een woord");
String w = scan.nextLine();
list.add(w);
spel.spelGedaan();
} while (!spel.isSpelGedaan() == false);
for(String w: list){
System.out.println(w);
}
System.out.println("gedaan");
[/CPP]
graag jullie hulp, mag ook een andere oplosiing zijn