Question

I am confused about how to code this. I have tried multiple ways of coding this...

I am confused about how to code this. I have tried multiple ways of coding this and nothing has worked for me. If someone could help that would be great thanks.

/*Chess Board:

You will also create 5 "lanes" of "pieces" and each lane has that number of pieces on it;
i.e. lane 5 = 5 pieces, lane 4 = 4 pieces, etc.
The user and the computer can take any number of pieces from one lane.
The object is to not take the last piece. Will it matter who goes first?*/

import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Scanner;

public class ChessBoard{

public static void main(String str[]) throws IOException   {
  
Scanner scan = new Scanner (System.in);
  
//ArrayList<String> lane = new ArrayList<String>();
  
//String lane5 = ("O", "O", "O", "O", "O");
//String lane4 = ("O", "O", "O", "O");
//String lane3 = ("O", "O", "O");
//String lane2 = ("O", "O");
//String lane1 = ("O");
int lane5[] = {0,0,0,0,0};
int lane4[] = {0,0,0,0};
int lane3[] = {0,0,0};
int lane2[] = {0,0};
int lane1[] = {0};

int lanenum;
int piecenum;
System.out.println("Please select a lane that you want to take from");
System.out.println("How many do you want to take? Selecet a number 1 - 3.");
lanenum = scan.nextInt();

if (lanenum == 5) {
for (int i = 0; i < lane5.length; i++) {
//lane5.length().remove(lanenum);
lane5 = lane5[i] - piecenum;
}
System.out.println(lane5);
}
else if (lanenum == 4) {
for (int i = 0; i < lane4.length; i++) {
//lane4.length().remove(lanenum);
lane4 = lane4[i] - piece;
}
System.out.println(lane4);
}
else if (lanenum == 3) {
for (int i = 0; i < lane3.length; i++) {
//lane3.length().remove(lanenum);
lane3 = lane3[i] - piecenum;
}
System.out.println(lane3);
}
else if (lanenum == 2) {
for (int i = 0; i < lane2.length; i++) {
//lane2.length().remove(lanenum);
lane2 = lane2[i] - piecenum;
}
System.out.println(lane2);
}
else if (lanenum == 1) {
for (int i = 0; i < lane1.length; i++) {
//lane1.length().remove(lanenum);
lane1 = lane1[i] - piecenum;
}
System.out.println(lane1);
}
else {
System.out.println("Please enter the number of a lane");
}
  
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Scanner;

public class ChessBoard{

public static void main(String str[]) throws IOException   {
  
Scanner scan = new Scanner (System.in);

int lane5[] = {0,0,0,0,0};
int lane4[] = {0,0,0,0};
int lane3[] = {0,0,0};
int lane2[] = {0,0};
int lane1[] = {0};

int lanenum;
int piecenum;

System.out.println("Please select a lane that you want to take from");

lanenum = scan.nextInt();

System.out.println("How many do you want to take? Selecet a number 1 - 3.");

piecenum=scan.nextInt();

if (lanenum == 5&&piecenum<=5)

{

lane5 = removeThePieces(lane5, piecenum);

System.out.println(lane5);

}else if

(lanenum == 4&&piecenum<=4)

{

lane4 = removeThePieces(lane4, piecenum);

System.out.println(lane4);

}

else if(lanenum == 3&&piecenum<=3)

{

lane3 = removeThePieces(lane3, piecenum);

System.out.println(lane3);

}

else if(lanenum == 2&&piecenum<=2)

{

lane2 = removeThePieces(lane2, piecenum);

System.out.println(lane2);

}

else if(lanenum == 1&&piecenum<=1)

{

lane1 = removeThePieces(lane1, piecenum);

System.out.println(lane1);

}

}//end of main

public static int[] removeThePiecet(int[] arr,

                                          int number)

    {

int[] anotherArray = new int[arr.length - number];//create another array

for (int i = 0, k = 0; i < arr.length-number; i++)

{

anotherArray[k++] = arr[i];

}

return anotherArray;

}//end of function

}//end of class

Add a comment
Know the answer?
Add Answer to:
I am confused about how to code this. I have tried multiple ways of coding this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have this code done in two methods, but it has to be done in one,...

    I have this code done in two methods, but it has to be done in one, and I can not figure out how to have it work and run correctly in one method. Chess Board: You will also create 5 "lanes" of "pieces" and each lane has that number of pieces on it; i.e. lane 5 = 5 pieces, lane 4 = 4 pieces, etc. The user and the computer can take any number of pieces from one lane. The...

  • I have spent so much time on this and I am having trouble getting all the...

    I have spent so much time on this and I am having trouble getting all the methods to work together correctly to run the code right, and I am not sure what is wrong with it. /* You will recreate one or two versions of the logic game shown in the Algorithms movie and you will ask which one the user would like to play. Upon completion of the game, display who won and ask if they would like to...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • Look for some finshing touches java help with this program. I just two more things added...

    Look for some finshing touches java help with this program. I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence. import java.util.Random; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.List; import java.util.Collections; public class main { public static void main(String[] args) { List < Sequence > list =...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • how would i use test.add because i would like to use add import java.io.File; import java.io.FileNotFoundException;...

    how would i use test.add because i would like to use add import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class checkFruit { private List<String> tests; public List<String> getFruit(String fruits) { tests = new ArrayList<String>(Arrays.asList(fruits.split(","))); for (String test : tests) { System.out.println(test); tests.add()//how would i use add here } return tests; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter file name: "); File file = new File(in.nextLine()); try { checkFruit...

  • My Question is: I have to modify this program, even a small modification is fine. Can...

    My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT