The Student Room Group

Higher Computing Coursework Task Help

Scroll to see replies

What if A and B crash an equal number of times, greater than any of C-F?
Reply 41
Original post by TheUnbeliever
What if A and B crash an equal number of times, greater than any of C-F?


The method I used can't choose between levels if more than one level has the max crashes (I think it would only remember the first level it check, so if Level A and Level F had the same amount of crashes, it would flag Level A as having the most crashes), however the program should display how many times each level crashed, so the user should be able to see if two or more levels have crashed the same number of times. I can't remember what the test data values were that were given by the SQA but I don't think it would cause such an issue.

If it does, I would probably use either an IF statement or a case statement to check if any other levels has the same amount of crashes, or when assigning a level to the most crashes, it would assign letters (a - f) for the levels that crashed the same amount of times.

Good question though.
Original post by JohnW1995
Good question though.


And a good answer! :smile: Of course, you should go by the specification rather than the test data, but I was mostly curious whether it was something you'd considered.
Reply 43
Hey guys i have an issue i've been stuck on for a while now with this coursework task. Heres my code

valid = False

Do
For Counter = 1 To number_of_string
level_crashed = LCase$(level_crashes)

level_crashed = Mid$(level_crashes, Counter, 1)

level_crashed = Asc(level_crashes)



If level_crashed = 97 >= 102 Then
valid = True
valid_data = Chr$(level_crashed)
Else: MsgBox ("a level you have entered does not exist")
Call get_user_data(level_crashes, number_of_string)
End If
Next Counter
Loop Until valid = True

lstoutput1.AddItem valid_data


This is only a small section to test that the letters are within a-f and everytime i try and fix it it comes up as my msgbox saying the level doesn't exist. Can anybody help me hint out whats wrong with it? Or give me any advice? I know that you need to make it all lowercase so it's only one range of data and then convert that to ASCII then do an if to see if it's within range
Original post by Mr blic
If level_crashed = 97 >= 102 Then

Interesting :p: It's been too long since I used Visual Basic, so I don't know what the exact result of that is, but it's not what you want.

level_crashed >= 97 And level_crashed <= 102
Reply 45
Oooo thank you that worked. :smile: See I dread going to class to do this task cause i can never get my head around little things that take me ages to get past. But thanks a lot that worked. :smile:
Reply 46
Original post by JohnW1995
To find the most crashes you would use an IF statement inside a fixed loop, we used Visual Basic but the method works regardless of your chosen programming language.
Assuming you used the following variables:

Counter(5)
Found As Boolean
i As Integer
MaxCrashes As Integer
MaxPosition As String

You could use the following algorithm to find the most crashes:

MaxCrashes = Counter(0)
For i = 1To 5
[INDENT]If Counter(i) > MaxCrashes Then[/INDENT]
[INDENT][INDENT]MaxCrashes = Counter(i)[/INDENT][/INDENT]
[INDENT]End If[/INDENT]

Next i

So the pseudocode for this (regarding this program) would look similar to this:

Set max crashes to first position of array (here you are assuming that the first value is the biggest)
Start loop for items in array (in this case there are 6 items)
If current position in array is bigger than the max crashes then
Max crashes = current position in array
End if
End loop

With respect to matching the most crashes with the level it belongs to you can use a case statement that looks similar to this:

Select Case MaxCrashes
[INDENT]Case Is = Counter(0)[/INDENT]
[INDENT][INDENT]MaxPosition = "A"[/INDENT][/INDENT]
[INDENT]Case Is = Counter(1)[/INDENT]
[INDENT][INDENT]MaxPosition = "B"[/INDENT][/INDENT]
and so on...
Again with this step, it can be used within any programming environment so long as you understand the method.


in java please not done visual basic in 2 years complete blur to me :colondollar:
Original post by MarkP2470
in java please not done visual basic in 2 years complete blur to me :colondollar:


'Select Case' is 'switch'; otherwise, everything pretty much translates as expected.
Reply 48
Original post by JohnW1995
The method I used can't choose between levels if more than one level has the max crashes (I think it would only remember the first level it check, so if Level A and Level F had the same amount of crashes, it would flag Level A as having the most crashes), however the program should display how many times each level crashed, so the user should be able to see if two or more levels have crashed the same number of times. I can't remember what the test data values were that were given by the SQA but I don't think it would cause such an issue.

If it does, I would probably use either an IF statement or a case statement to check if any other levels has the same amount of crashes, or when assigning a level to the most crashes, it would assign letters (a - f) for the levels that crashed the same amount of times.

Good question though.


yeh if a and f crash at the same time it has to. display a and f.. :/
Reply 49
Original post by JohnW1995

Select Case MaxCrashes
[INDENT]Case Is = Counter(0)[/INDENT]
[INDENT][INDENT]MaxPosition = "A"[/INDENT][/INDENT]
[INDENT]Case Is = Counter(1)[/INDENT]
[INDENT][INDENT]MaxPosition = "B"[/INDENT][/INDENT]
and so on...
Again with this step, it can be used within any programming environment so long as you understand the method.


yeh i did this changed it to java to look like this:
switch (Max)
{
case = crashCount[0];
MaxPosition=("A");
case = crashCount[1];
MaxPosition=("B");
case = crashCount[2];
MaxPosition=("C");
case = crashCount[3];
MaxPosition=("D");
case = crashCount[4];
MaxPosition=("E");
case = crashCount[5];
MaxPosition=("F");
}

and i got this error :
illegal start of expression

so what on earth have i done wrong????? :s-smilie:
(edited 12 years ago)
That's not (even close to) the right syntax for a switch statement. I'm on my phone, so I won't link directly, but Googling for something like 'switch statement Java' should help you.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html may help :smile:

switch (var) {
case a:
doStuff();
break;
case b:
doStuff();
break;
default:
doStuff();
}


Note that the switch statement will not accept strings in Java 6, as it was a feature added in Java 7 - it's fairly likely your school will still be running Java 6. Char works for switch statements though, so you may be able to use that.

(As a side note, use camel case for variables! i.e. int someVariable; and not int SomeVariable; - for classes, the first letter should be a capital, i.e. public SomeClass. It's not a necessity but it's good practice to follow the conventions of the language you're working in - I saw switch (Max) in your post and it upset me :frown: xD)
(edited 12 years ago)
Reply 52
right i think im confusing some people with what part of code im stuck on i have made the program take letters, and only accept the letters a-f, display how many times each level crashed in a table and find and show how many times the level crashed the most all i need to do is create a code that finds which level crashed the most and display it

Example of what my output looks like:

Level Times Crashed
a 3
b 2
c 2
d 2
e 1
f 0
The level that crashed most was

And it appeared 3 times

so all i need to display is "Level A" is the space between "The level that crashed most was" and "
And it appeared 3 times"

Help please :frown:
Reply 53
Original post by MarkP2470
right i think im confusing some people with what part of code im stuck on i have made the program take letters, and only accept the letters a-f, display how many times each level crashed in a table and find and show how many times the level crashed the most all i need to do is create a code that finds which level crashed the most and display it

Example of what my output looks like:

Level Times Crashed
a 3
b 2
c 2
d 2
e 1
f 0
The level that crashed most was

And it appeared 3 times

so all i need to display is "Level A" is the space between "The level that crashed most was" and "
And it appeared 3 times"

Help please :frown:


You could use another 'switch statement'. I don't know anything about Java, but I can put part of the code on in Visual Basic and you could convert it to Java the same way you done earlier. You just have to check what counter matches MaxCrashes. Assuming you are using an array for the counters and the variable called 'MaxPosition' for which level crashed the most, the Visual Basic code would look like this:

Select Case MaxCrashes
[INDENT]Case Is = Counter(0)[/INDENT]
[INDENT][INDENT]MaxPosition = "Level A"[/INDENT][/INDENT]
[INDENT]Case Is = Counter(1)[/INDENT]
[INDENT][INDENT]MaxPosition = "Level B"[/INDENT][/INDENT]
and so on...
End Select

Then you could just display MaxPosition along with your display message. If that doesn't work you could try using an IF statement and just repeating ElseIf until you have covered all the levels in the IF statement.

Not sure if it will be much help to you because your using Java, but I imagine the principals of it are the same.
(edited 12 years ago)
Reply 54
The switch code:
switch (MaxPosition) {
case 1: Counter = "Level A";
break;
case 2: Counter = "Level B";
break;
case 3: Counter = "Level C";
break;
case 4: Counter = "Level D";
break;
case 5: Counter = "Level E";
break;
case 6: Counter = "Level F";
break;
default: Counter = "Invalid level";
break;
}

System.out.println(Counter);

The result when i put aaabbccdde into the input box:

Level Times Crashed
a 3
b 2
c 2
d 2
e 1
f 0
The level that crashed most was
Level C
And it appeared 3 times

changes i need to make?
(edited 12 years ago)
Reply 55
Original post by MarkP2470
The switch code:
switch (MaxPosition) {
case 1: Counter = "Level A";
break;
case 2: Counter = "Level B";
break;
case 3: Counter = "Level C";
break;
case 4: Counter = "Level D";
break;
case 5: Counter = "Level E";
break;
case 6: Counter = "Level F";
break;
default: Counter = "Invalid level";
break;
}

System.out.println(Counter);

The result when i put aaabbccdde into the input box:

Level Times Crashed
a 3
b 2
c 2
d 2
e 1
f 0
The level that crashed most was
Level C
And it appeared 3 times

changes i need to make?


Like I said before, I don't know anything about Java, so I can't really tell if the 'Switch' statement is correct, but it looks as if you are assigning "Level A" to the counter, whether that's how it works in Java, I do not know. I think where you have got Counter = "Level A", you should be saying something along the lines of MaxCrashes = Counter(0), then MaxPosition = "Level A". One problem, at least I think it's a problem, is that your 'switch' is examining MaxPosition, when it should be examining MaxCrashes. Try making these changes and let me know if they work.

With regard to it appearing 3 times, make sure you have not put the code for displaying this inside the loop, that's the only reason I can think of that would cause it to loop three times.

Let me know how you get on.
Reply 56
Ive done it!!!!! no more harrasment from me now youll be please to know :L
(edited 12 years ago)
This is just a quick question, i'm using Visual Basic, roughly how many arrays should I use in the program? I know I need one for the crash counter and the letter being extracted, but I'm not sure if I need another one elsewhere.
Reply 58
Original post by lewis_dicks
This is just a quick question, i'm using Visual Basic, roughly how many arrays should I use in the program? I know I need one for the crash counter and the letter being extracted, but I'm not sure if I need another one elsewhere.


Yes, you do need another one. You need a string array for the levels that crashed, as the user has to enter three 10-character strings containing the levels that crashed, the LevelsCrashed string array should allow for three items, i.e.

Dim LevelsCrashed(3) As String
I managed to work it out, but I used four arrays, one for the letter being extracted, one for the ASCII value of that letter, one for the crash counters and one for displaying the characters.

Quick Reply

Latest

Trending

Trending