Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Beginner Java Code Trouble
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
saucy_pup




PostPosted: Thu Dec 21, 2017 6:07 pm   Post subject: Beginner Java Code Trouble

Hi guys so I'm new to the forums and programming in general so I'll apologize in advance..
I've compared my code below to other code using the same operators etc but I can't identify why mine is hitting compilation error.

My criteria for the program is to create a card game in which 2 players compare a card each seven times.
My attempt was to break the task down with a boolean operator 'playing' to establish if the game was over.
While 'playing' is true the cards would be compared and a victor would be declared each round the for loop initiates,
until 'playing' is false and the tallied results are compared.

Any insight or point in the right direction would be just spectacular.
**ofc the line numbers on the left aren't in the code, I've also attached a notepad file without the numbers.
---------------------------------------------------------------------------------
1 package javaapplication1;
2 public class JavaApplication1 {
3
4 public static void main(String[] args) {
5 int[] playerOneCards = {10, 6, 8, 9, 7, 12, 7};
6 int[] playerTwoCards = {7, 6, 9, 5, 2, 8, 11};
7 boolean playing;
8 int playerOneVictory = 0;
9 int playerTwoVictory = 0;
10 int round = 0;
11
12 if(round < 7){playing = true;}
13 else {playing = false;}
14 if(playing == true){
15 for (round = 0; round<8; round++){
16 if(playerOneCards[round]>playerTwoCards[round]){
17 playerOneVictory += 1;}
18 else if(playerOneCards[round]<playerTwoCards[round]){
19 playerTwoVictory += 1;}}}
20
21 if (playing == false)&&(playerOneCards > playerTwoCards){
22 System.out.println("Player One wins! ! He/She won "+playerOneVictory+" rounds beating Player Two who won "+playerTwoVictory+" rounds! ");
23 System.out.print("Goodbye!");}
24
25 else if(playing == false)&&(playerOneCards<playerTwoCards){
26 System.out.println("Player Two wins! ! He/She won "+playerOneVictory+" rounds beating Player Two who won "+playerTwoVictory+" rounds!");
27 System.out.println("Goodbye!");}
28
29 }
30 }



javaExercise.txt
 Description:

Download
 Filename:  javaExercise.txt
 Filesize:  1.3 KB
 Downloaded:  33 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: