Thread: Struggling W Programming 2 HW

Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13
  1. #11  
    Banned

    Join Date
    Aug 2016
    Posts
    242
    Thanks given
    109
    Thanks received
    61
    Rep Power
    0
    Quote Originally Posted by A Mage View Post
    This.
    If you were in class, your teacher should've gone through with you the methods etc needed to do this snippet?
    I can't imagine they'd just expect you to come up with it, especially if it doesn't seem like an overly high level of coding.
    I had a teacher who told us to refer to java docs if we weren't informed enough by his lectures sooo not 100% unrealistic for him to not have received enough info in class and needed help.
    Reply With Quote  
     

  2. Thankful user:


  3. #12  
    Registered Member

    Join Date
    Apr 2016
    Posts
    309
    Thanks given
    294
    Thanks received
    64
    Rep Power
    275
    I asked for help, she said she can't do much, I looked through my notes and still can't figure it out. I've been trying for 3 days now.

    Edit: I still need this please
    Reply With Quote  
     

  4. Thankful user:


  5. #13  
    Banned

    Join Date
    Oct 2009
    Posts
    734
    Thanks given
    168
    Thanks received
    54
    Rep Power
    0
    This is not perfect, I ran out of patience half way, but the general concept of bowling seems to work. Enter 4 players names and the scores will be calculated at random for 10 frames.

    X = strike
    / = spare
    - = neither

    Code:
    package bowling;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class Bowling {
    	
    	private static Random random = new Random();
    	
    	public static void main(String[] args) {
    		String[] names = new String[4];
    		
    		Scanner scanner = null;
    		
    		try {
    			scanner = new Scanner(System.in);
    			System.out.println("Enter player 1's name.");
    			names[0] = scanner.nextLine();
    			System.out.println("Enter player 2's name.");
    			names[1] = scanner.nextLine();
    			System.out.println("Enter player 3's name.");
    			names[2] = scanner.nextLine();
    			System.out.println("Enter player 4's name.");
    			names[3] = scanner.nextLine();
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			scanner.close();
    		}
    		
    		int total = 0;
    		int player_one_score = 0;
    		int player_two_score = 0;
    		int player_three_score = 0;
    		int player_four_score = 0;
    		
    		
    		for (int turn = 0; turn < 10; turn++) {
    			System.out.println("~~~~~~~~~~~~~~~~~~~~~ Frame " + (int) (turn + 1) + " ~~~~~~~~~~~~~~~~~~~~~");
    			for (int player = 0; player < names.length; player++) {
    				System.out.println(names[player]);
    				int[] score = new int[3];
    
    				int index = 0;
    				while (index < 2 && score[0] + score[1] != 10) {
    					switch (index) {
    					case 0:
    						score[0] = random.nextInt(10) + 1;
    						break;
    					case 1:
    						score[1] = random.nextInt(Math.abs(10 - score[0]) + 1);
    						break;
    					}
    					//System.out.println("score[0] " + score[0]);
    					//System.out.println("score[1] " + score[1]);
    					//System.out.println("score[2] " + score[2]);
    					index++;
    				}
    				
    				if (player == 0) {
    					player_one_score += (int) (score[0] + score[1]);
    				} else if (player == 1) {
    					player_two_score += (int) (score[0] + score[1]);
    				} else if (player == 2) {
    					player_three_score += (int) (score[0] + score[1]);
    				} else if (player == 3) {
    					player_four_score += (int) (score[0] + score[1]);
    				}
    				
    				if (score[0] == 10) {
    					System.out.println("X");
    					
    				} else if ((int) (score[0] + score[1]) == 10) {
    					System.out.println("/ " + (int) (score[0] + score[1]));
    					
    				} else if ((int) (score[0] + score[1]) < 10) {
    					System.out.println("- " + (int) (score[0] + score[1]));
    					
    					
    				} else if ((int) (score[0] + score[1]) > 10) {
    					System.out.println("Error");
    				}
    				
    			}
    		}
    		
    		total = player_one_score + player_two_score + player_three_score + player_four_score;
    		System.out.println("player_one_score: " + player_one_score);
    		System.out.println("player_two_score: " + player_two_score);
    		System.out.println("player_three_score: " + player_three_score);
    		System.out.println("player_four_score: " + player_four_score);
    		System.out.println("total: " + total);
    	}
    
    }
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. The struggle of programming
    By Techkid in forum Application Development
    Replies: 16
    Last Post: 02-21-2014, 11:09 AM
  2. Awesome Tutorial Program
    By purepkownage in forum Downloads
    Replies: 8
    Last Post: 10-30-2010, 10:30 PM
  3. Struggle,,,,,hate on it
    By Beh3moth in forum Showcase
    Replies: 2
    Last Post: 11-09-2007, 03:38 PM
  4. Programming for cash - Java / PHP
    By Jeebals in forum RS2 Server
    Replies: 4
    Last Post: 10-29-2007, 10:27 AM
  5. Replies: 12
    Last Post: 07-10-2007, 03:08 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •