Organize musicians into rows, with weight and population restrictionsSlicing up an image into rows and...

How to prevent YouTube from showing already watched videos?

Organic chemistry Iodoform Reaction

Can a Bard use an arcane focus?

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Calculating the number of days between 2 dates in Excel

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Teaching indefinite integrals that require special-casing

Stereotypical names

My boss asked me to take a one-day class, then signs it up as a day off

Books on the History of math research at European universities

A known event to a history junkie

Would it be legal for a US State to ban exports of a natural resource?

Resetting two CD4017 counters simultaneously, only one resets

Is a naturally all "male" species possible?

How do I repair my stair bannister?

Should my PhD thesis be submitted under my legal name?

Can a malicious addon access internet history and such in chrome/firefox?

Adding empty element to declared container without declaring type of element

How can I successfully establish a nationwide combat training program for a large country?

Is there enough fresh water in the world to eradicate the drinking water crisis?

No idea how to draw this using tikz

The most efficient algorithm to find all possible integer pairs which sum to a given integer

Word describing multiple paths to the same abstract outcome

How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?



Organize musicians into rows, with weight and population restrictions


Slicing up an image into rows and columns in JavaCreate and organize some classes (hierarchy)Does RunLengthEncoding class provide abstraction and encapsulation?Streamlining a method to run fasterDice-throwing gameExtract a range of rows from one file into anotherFill 2D array recursivelyCompare 2 unordered, rooted trees for shape-isomorphismFollow-up 1: Compare 2 unordered, rooted trees for shape-isomorphismBovine Shuffle using a queue (USACO Dec 2017 Silver)













1












$begingroup$


So I just completed this project for my java programming class and was wondering if there was any way I could streamline it to really impress my professor. Here were the instructions, followed by my code.




The University of Miami's "Band of the Hour" needs a program to organize where the musicians will stand when they play at away games. Each away stadium is different, so when they arrive the conductor gets the following information from the local organizer:



The number of rows they have to stand on. The maximum number of rows is 10. The rows are labelled with capital letters, 'A', 'B', 'C', etc.



For each row, the number of positions in the row. The maximum number of positions is 8. The positions are numbered with integers, 1, 2, 3, etc.



The conductor then starts assigning people to positions, but is constrained by weight limits: Musicians, fully clothed and holding their instruments, weigh from 45kg to 200kg, and the total weight of a row may not exceed 100kg per position (e.g., a row with 5 positions may not have more than 500kg of musicians on it). The conductor wants a program that allows musicians to be added and removed from positions, while ensuring the constraints are all met. At any stage the conductor wants to be able to see the current assignment - the weight in each position (0kg for vacant positions) and the total & average weight for each row.



The program must be menu driven, with options to:




  • Add a musician (by weight) to a vacant position.

  • Remove a musician from an occupied position.

  • Print the current assignment.

  • Exit (so the musicians can start playing)


The program must be reasonably idiot proof:




  • Menu options must be accepted in upper and lower case.

  • Row letters must be accepted in upper and lower case.

  • All input must be checked to be in range, and if not the user must be asked to input again.

  • You may assume that numeric input will be syntactically correct.




import java.util.Scanner;

public class Main {

private static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args) {

//values

int positions;
int rowNumber;
char userInput;
char rowLetter;
double musicianWeight = 0;
double tot = 0;
int j;
int i;

System.out.println();
System.out.println("Welcome to the Band of the Hour");
System.out.println("-------------------------------");

//create array

System.out.print("Please enter number of rowstt: ");
rowNumber = keyboard.nextInt();

double[][] positionsArray = new double[rowNumber][5];
int[] rowPositions = new int[rowNumber];

while (rowNumber < 1 || rowNumber > 10) {
System.out.print("ERROR: Out of range, try again : ");
rowNumber = keyboard.nextInt();
}
for (int row = 0; row < rowNumber; row++) {
System.out.print("Please enter the number of positions in row " + (char) (row + (int) 'A') + " : ");
positions = keyboard.nextInt();
rowPositions[row] = positions;
while (positions < 0 || positions > 8) {
System.out.print("ERROR: Out of range, try again : ");
positions = keyboard.nextInt();
}
positionsArray = new double[rowNumber][positions];
}
do {
System.out.println();
System.out.print(" (A)dd, (R)emove, (P)rint e(X)it : ");
userInput = keyboard.next().charAt(0);
userInput = Character.toUpperCase(userInput);

//add musician

switch (userInput) {
case 'A': {
System.out.print("Please enter row letter : ");
while (true) {
rowLetter = keyboard.next().charAt(0);
rowLetter = Character.toUpperCase(rowLetter);
if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}
System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");
positions = keyboard.nextInt();
while (true) {
if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])
break;
System.out.print("ERROR: Out of range, try again : ");
}
if (positionsArray[rowLetter - 'A'][positions - 1] != 0) {
System.out.println("ERROR: There is already a musician there.");
break;
}
else {
System.out.print("Please enter weight (45.0 to 200.0) : ");
while (true) {
musicianWeight = keyboard.nextDouble();
if (musicianWeight >= 45.0 && musicianWeight <= 200.0)
break;
System.out.print("Error: Out of range, try again : ");
}
}
tot = tot + musicianWeight;
if (tot > 500) {
System.out.println("ERROR: That would exceed the average weight limit.");
}
else {
positionsArray[rowLetter - 'A'][positions - 1] = musicianWeight;
System.out.println("********** Musician added");
}
}
break;

//remove musician

case 'R' : {
System.out.print("Please enter row letter : ");

while (true) {
rowLetter = keyboard.next().charAt(0);

rowLetter = Character.toUpperCase(rowLetter);

if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}

System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");

while (true) {
positions = keyboard.nextInt();

if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])

break;

System.out.print("ERROR: Out of range, try again : ");

}

if (positionsArray[rowLetter-'A'][positions-1] == 0)


System.out.println("ERROR: That spot is vacant.");

else {

positionsArray[rowLetter-'A'][positions-1] = 0;

System.out.print("****** Musician removed.");
System.out.println();
}
}

//print layout
break;
case 'P' : {
System.out.println();
for (i = 0; i < rowNumber; i++) {
System.out.print((char) (i + 65) + ": ");
tot = 0;
for (j = 0; j < rowPositions[i]; j++) {
System.out.printf("%3.1ft", positionsArray[i][j]);
tot += positionsArray[i][j];
}
System.out.printf("tt[%6.1f,%6.1f]n", tot, (tot / rowPositions[i]));
}
break;
}

//end program
case 'X' : {
System.exit(0);
}
default :
System.out.print("ERROR: Invalid option, try again :");
break;
}
} while (userInput != 'X');
}
}


How can I streamline this code?










share|improve this question









New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
    $endgroup$
    – Roland Illig
    18 hours ago
















1












$begingroup$


So I just completed this project for my java programming class and was wondering if there was any way I could streamline it to really impress my professor. Here were the instructions, followed by my code.




The University of Miami's "Band of the Hour" needs a program to organize where the musicians will stand when they play at away games. Each away stadium is different, so when they arrive the conductor gets the following information from the local organizer:



The number of rows they have to stand on. The maximum number of rows is 10. The rows are labelled with capital letters, 'A', 'B', 'C', etc.



For each row, the number of positions in the row. The maximum number of positions is 8. The positions are numbered with integers, 1, 2, 3, etc.



The conductor then starts assigning people to positions, but is constrained by weight limits: Musicians, fully clothed and holding their instruments, weigh from 45kg to 200kg, and the total weight of a row may not exceed 100kg per position (e.g., a row with 5 positions may not have more than 500kg of musicians on it). The conductor wants a program that allows musicians to be added and removed from positions, while ensuring the constraints are all met. At any stage the conductor wants to be able to see the current assignment - the weight in each position (0kg for vacant positions) and the total & average weight for each row.



The program must be menu driven, with options to:




  • Add a musician (by weight) to a vacant position.

  • Remove a musician from an occupied position.

  • Print the current assignment.

  • Exit (so the musicians can start playing)


The program must be reasonably idiot proof:




  • Menu options must be accepted in upper and lower case.

  • Row letters must be accepted in upper and lower case.

  • All input must be checked to be in range, and if not the user must be asked to input again.

  • You may assume that numeric input will be syntactically correct.




import java.util.Scanner;

public class Main {

private static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args) {

//values

int positions;
int rowNumber;
char userInput;
char rowLetter;
double musicianWeight = 0;
double tot = 0;
int j;
int i;

System.out.println();
System.out.println("Welcome to the Band of the Hour");
System.out.println("-------------------------------");

//create array

System.out.print("Please enter number of rowstt: ");
rowNumber = keyboard.nextInt();

double[][] positionsArray = new double[rowNumber][5];
int[] rowPositions = new int[rowNumber];

while (rowNumber < 1 || rowNumber > 10) {
System.out.print("ERROR: Out of range, try again : ");
rowNumber = keyboard.nextInt();
}
for (int row = 0; row < rowNumber; row++) {
System.out.print("Please enter the number of positions in row " + (char) (row + (int) 'A') + " : ");
positions = keyboard.nextInt();
rowPositions[row] = positions;
while (positions < 0 || positions > 8) {
System.out.print("ERROR: Out of range, try again : ");
positions = keyboard.nextInt();
}
positionsArray = new double[rowNumber][positions];
}
do {
System.out.println();
System.out.print(" (A)dd, (R)emove, (P)rint e(X)it : ");
userInput = keyboard.next().charAt(0);
userInput = Character.toUpperCase(userInput);

//add musician

switch (userInput) {
case 'A': {
System.out.print("Please enter row letter : ");
while (true) {
rowLetter = keyboard.next().charAt(0);
rowLetter = Character.toUpperCase(rowLetter);
if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}
System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");
positions = keyboard.nextInt();
while (true) {
if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])
break;
System.out.print("ERROR: Out of range, try again : ");
}
if (positionsArray[rowLetter - 'A'][positions - 1] != 0) {
System.out.println("ERROR: There is already a musician there.");
break;
}
else {
System.out.print("Please enter weight (45.0 to 200.0) : ");
while (true) {
musicianWeight = keyboard.nextDouble();
if (musicianWeight >= 45.0 && musicianWeight <= 200.0)
break;
System.out.print("Error: Out of range, try again : ");
}
}
tot = tot + musicianWeight;
if (tot > 500) {
System.out.println("ERROR: That would exceed the average weight limit.");
}
else {
positionsArray[rowLetter - 'A'][positions - 1] = musicianWeight;
System.out.println("********** Musician added");
}
}
break;

//remove musician

case 'R' : {
System.out.print("Please enter row letter : ");

while (true) {
rowLetter = keyboard.next().charAt(0);

rowLetter = Character.toUpperCase(rowLetter);

if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}

System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");

while (true) {
positions = keyboard.nextInt();

if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])

break;

System.out.print("ERROR: Out of range, try again : ");

}

if (positionsArray[rowLetter-'A'][positions-1] == 0)


System.out.println("ERROR: That spot is vacant.");

else {

positionsArray[rowLetter-'A'][positions-1] = 0;

System.out.print("****** Musician removed.");
System.out.println();
}
}

//print layout
break;
case 'P' : {
System.out.println();
for (i = 0; i < rowNumber; i++) {
System.out.print((char) (i + 65) + ": ");
tot = 0;
for (j = 0; j < rowPositions[i]; j++) {
System.out.printf("%3.1ft", positionsArray[i][j]);
tot += positionsArray[i][j];
}
System.out.printf("tt[%6.1f,%6.1f]n", tot, (tot / rowPositions[i]));
}
break;
}

//end program
case 'X' : {
System.exit(0);
}
default :
System.out.print("ERROR: Invalid option, try again :");
break;
}
} while (userInput != 'X');
}
}


How can I streamline this code?










share|improve this question









New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
    $endgroup$
    – Roland Illig
    18 hours ago














1












1








1





$begingroup$


So I just completed this project for my java programming class and was wondering if there was any way I could streamline it to really impress my professor. Here were the instructions, followed by my code.




The University of Miami's "Band of the Hour" needs a program to organize where the musicians will stand when they play at away games. Each away stadium is different, so when they arrive the conductor gets the following information from the local organizer:



The number of rows they have to stand on. The maximum number of rows is 10. The rows are labelled with capital letters, 'A', 'B', 'C', etc.



For each row, the number of positions in the row. The maximum number of positions is 8. The positions are numbered with integers, 1, 2, 3, etc.



The conductor then starts assigning people to positions, but is constrained by weight limits: Musicians, fully clothed and holding their instruments, weigh from 45kg to 200kg, and the total weight of a row may not exceed 100kg per position (e.g., a row with 5 positions may not have more than 500kg of musicians on it). The conductor wants a program that allows musicians to be added and removed from positions, while ensuring the constraints are all met. At any stage the conductor wants to be able to see the current assignment - the weight in each position (0kg for vacant positions) and the total & average weight for each row.



The program must be menu driven, with options to:




  • Add a musician (by weight) to a vacant position.

  • Remove a musician from an occupied position.

  • Print the current assignment.

  • Exit (so the musicians can start playing)


The program must be reasonably idiot proof:




  • Menu options must be accepted in upper and lower case.

  • Row letters must be accepted in upper and lower case.

  • All input must be checked to be in range, and if not the user must be asked to input again.

  • You may assume that numeric input will be syntactically correct.




import java.util.Scanner;

public class Main {

private static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args) {

//values

int positions;
int rowNumber;
char userInput;
char rowLetter;
double musicianWeight = 0;
double tot = 0;
int j;
int i;

System.out.println();
System.out.println("Welcome to the Band of the Hour");
System.out.println("-------------------------------");

//create array

System.out.print("Please enter number of rowstt: ");
rowNumber = keyboard.nextInt();

double[][] positionsArray = new double[rowNumber][5];
int[] rowPositions = new int[rowNumber];

while (rowNumber < 1 || rowNumber > 10) {
System.out.print("ERROR: Out of range, try again : ");
rowNumber = keyboard.nextInt();
}
for (int row = 0; row < rowNumber; row++) {
System.out.print("Please enter the number of positions in row " + (char) (row + (int) 'A') + " : ");
positions = keyboard.nextInt();
rowPositions[row] = positions;
while (positions < 0 || positions > 8) {
System.out.print("ERROR: Out of range, try again : ");
positions = keyboard.nextInt();
}
positionsArray = new double[rowNumber][positions];
}
do {
System.out.println();
System.out.print(" (A)dd, (R)emove, (P)rint e(X)it : ");
userInput = keyboard.next().charAt(0);
userInput = Character.toUpperCase(userInput);

//add musician

switch (userInput) {
case 'A': {
System.out.print("Please enter row letter : ");
while (true) {
rowLetter = keyboard.next().charAt(0);
rowLetter = Character.toUpperCase(rowLetter);
if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}
System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");
positions = keyboard.nextInt();
while (true) {
if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])
break;
System.out.print("ERROR: Out of range, try again : ");
}
if (positionsArray[rowLetter - 'A'][positions - 1] != 0) {
System.out.println("ERROR: There is already a musician there.");
break;
}
else {
System.out.print("Please enter weight (45.0 to 200.0) : ");
while (true) {
musicianWeight = keyboard.nextDouble();
if (musicianWeight >= 45.0 && musicianWeight <= 200.0)
break;
System.out.print("Error: Out of range, try again : ");
}
}
tot = tot + musicianWeight;
if (tot > 500) {
System.out.println("ERROR: That would exceed the average weight limit.");
}
else {
positionsArray[rowLetter - 'A'][positions - 1] = musicianWeight;
System.out.println("********** Musician added");
}
}
break;

//remove musician

case 'R' : {
System.out.print("Please enter row letter : ");

while (true) {
rowLetter = keyboard.next().charAt(0);

rowLetter = Character.toUpperCase(rowLetter);

if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}

System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");

while (true) {
positions = keyboard.nextInt();

if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])

break;

System.out.print("ERROR: Out of range, try again : ");

}

if (positionsArray[rowLetter-'A'][positions-1] == 0)


System.out.println("ERROR: That spot is vacant.");

else {

positionsArray[rowLetter-'A'][positions-1] = 0;

System.out.print("****** Musician removed.");
System.out.println();
}
}

//print layout
break;
case 'P' : {
System.out.println();
for (i = 0; i < rowNumber; i++) {
System.out.print((char) (i + 65) + ": ");
tot = 0;
for (j = 0; j < rowPositions[i]; j++) {
System.out.printf("%3.1ft", positionsArray[i][j]);
tot += positionsArray[i][j];
}
System.out.printf("tt[%6.1f,%6.1f]n", tot, (tot / rowPositions[i]));
}
break;
}

//end program
case 'X' : {
System.exit(0);
}
default :
System.out.print("ERROR: Invalid option, try again :");
break;
}
} while (userInput != 'X');
}
}


How can I streamline this code?










share|improve this question









New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




So I just completed this project for my java programming class and was wondering if there was any way I could streamline it to really impress my professor. Here were the instructions, followed by my code.




The University of Miami's "Band of the Hour" needs a program to organize where the musicians will stand when they play at away games. Each away stadium is different, so when they arrive the conductor gets the following information from the local organizer:



The number of rows they have to stand on. The maximum number of rows is 10. The rows are labelled with capital letters, 'A', 'B', 'C', etc.



For each row, the number of positions in the row. The maximum number of positions is 8. The positions are numbered with integers, 1, 2, 3, etc.



The conductor then starts assigning people to positions, but is constrained by weight limits: Musicians, fully clothed and holding their instruments, weigh from 45kg to 200kg, and the total weight of a row may not exceed 100kg per position (e.g., a row with 5 positions may not have more than 500kg of musicians on it). The conductor wants a program that allows musicians to be added and removed from positions, while ensuring the constraints are all met. At any stage the conductor wants to be able to see the current assignment - the weight in each position (0kg for vacant positions) and the total & average weight for each row.



The program must be menu driven, with options to:




  • Add a musician (by weight) to a vacant position.

  • Remove a musician from an occupied position.

  • Print the current assignment.

  • Exit (so the musicians can start playing)


The program must be reasonably idiot proof:




  • Menu options must be accepted in upper and lower case.

  • Row letters must be accepted in upper and lower case.

  • All input must be checked to be in range, and if not the user must be asked to input again.

  • You may assume that numeric input will be syntactically correct.




import java.util.Scanner;

public class Main {

private static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args) {

//values

int positions;
int rowNumber;
char userInput;
char rowLetter;
double musicianWeight = 0;
double tot = 0;
int j;
int i;

System.out.println();
System.out.println("Welcome to the Band of the Hour");
System.out.println("-------------------------------");

//create array

System.out.print("Please enter number of rowstt: ");
rowNumber = keyboard.nextInt();

double[][] positionsArray = new double[rowNumber][5];
int[] rowPositions = new int[rowNumber];

while (rowNumber < 1 || rowNumber > 10) {
System.out.print("ERROR: Out of range, try again : ");
rowNumber = keyboard.nextInt();
}
for (int row = 0; row < rowNumber; row++) {
System.out.print("Please enter the number of positions in row " + (char) (row + (int) 'A') + " : ");
positions = keyboard.nextInt();
rowPositions[row] = positions;
while (positions < 0 || positions > 8) {
System.out.print("ERROR: Out of range, try again : ");
positions = keyboard.nextInt();
}
positionsArray = new double[rowNumber][positions];
}
do {
System.out.println();
System.out.print(" (A)dd, (R)emove, (P)rint e(X)it : ");
userInput = keyboard.next().charAt(0);
userInput = Character.toUpperCase(userInput);

//add musician

switch (userInput) {
case 'A': {
System.out.print("Please enter row letter : ");
while (true) {
rowLetter = keyboard.next().charAt(0);
rowLetter = Character.toUpperCase(rowLetter);
if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}
System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");
positions = keyboard.nextInt();
while (true) {
if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])
break;
System.out.print("ERROR: Out of range, try again : ");
}
if (positionsArray[rowLetter - 'A'][positions - 1] != 0) {
System.out.println("ERROR: There is already a musician there.");
break;
}
else {
System.out.print("Please enter weight (45.0 to 200.0) : ");
while (true) {
musicianWeight = keyboard.nextDouble();
if (musicianWeight >= 45.0 && musicianWeight <= 200.0)
break;
System.out.print("Error: Out of range, try again : ");
}
}
tot = tot + musicianWeight;
if (tot > 500) {
System.out.println("ERROR: That would exceed the average weight limit.");
}
else {
positionsArray[rowLetter - 'A'][positions - 1] = musicianWeight;
System.out.println("********** Musician added");
}
}
break;

//remove musician

case 'R' : {
System.out.print("Please enter row letter : ");

while (true) {
rowLetter = keyboard.next().charAt(0);

rowLetter = Character.toUpperCase(rowLetter);

if (rowLetter - 'A' < rowNumber)
break;
System.out.print("ERROR: Out of range, try again : ");
}

System.out.print("Please enter position number (1 to " + rowPositions[rowLetter - 'A'] + " ) : ");

while (true) {
positions = keyboard.nextInt();

if (positions >= 0 && positions <= rowPositions[rowLetter - 'A'])

break;

System.out.print("ERROR: Out of range, try again : ");

}

if (positionsArray[rowLetter-'A'][positions-1] == 0)


System.out.println("ERROR: That spot is vacant.");

else {

positionsArray[rowLetter-'A'][positions-1] = 0;

System.out.print("****** Musician removed.");
System.out.println();
}
}

//print layout
break;
case 'P' : {
System.out.println();
for (i = 0; i < rowNumber; i++) {
System.out.print((char) (i + 65) + ": ");
tot = 0;
for (j = 0; j < rowPositions[i]; j++) {
System.out.printf("%3.1ft", positionsArray[i][j]);
tot += positionsArray[i][j];
}
System.out.printf("tt[%6.1f,%6.1f]n", tot, (tot / rowPositions[i]));
}
break;
}

//end program
case 'X' : {
System.exit(0);
}
default :
System.out.print("ERROR: Invalid option, try again :");
break;
}
} while (userInput != 'X');
}
}


How can I streamline this code?







java






share|improve this question









New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 17 hours ago









mdfst13

17.9k62157




17.9k62157






New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 hours ago









CorbinCorbin

62




62




New contributor




Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Corbin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
    $endgroup$
    – Roland Illig
    18 hours ago


















  • $begingroup$
    Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
    $endgroup$
    – Roland Illig
    18 hours ago
















$begingroup$
Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
$endgroup$
– Roland Illig
18 hours ago




$begingroup$
Welcome. You should read how to ask good questions. Your current question is not good since it doesn't describe what the code is supposed to do.
$endgroup$
– Roland Illig
18 hours ago










1 Answer
1






active

oldest

votes


















1












$begingroup$

Welcome to code review and thanks for sharing your code.



Here are some points to consider:





  • declare variables as close to their usage as possible.



    You declared (almost) all your variable at the beginning of your main method which makes it hard to improve your code later on.
    This applies especially to i and j which are used in for loops and should be declared inside them.




  • avoid short variable names.



    Will you remember what tot is in 6 month?




  • do not use the else branch of an if statement as an error handler. Instead of




            while (true) {
    rowLetter = keyboard.next().charAt(0);
    rowLetter = Character.toUpperCase(rowLetter);
    if (rowLetter - 'A' < rowNumber)
    break;
    System.out.print("ERROR: Out of range, try again : ");
    }



    it should be:



            boolean isInputValid = false;
    do {
    rowLetter = keyboard.next().charAt(0);
    rowLetter = Character.toUpperCase(rowLetter);
    isInputValid = (rowLetter - 'A' < rowNumber)
    if (!isInputValid)
    System.out.print("ERROR: Out of range, try again : ");
    } while (!isInputValid);



  • avoid magic numbers



    your code has some literals that need explanation: what is 5 in new double[rowNumber][5];?
    This should be a constant having a meaningful name:



       private static final int MAX_POSITION = 5;
    // ...
    public static void main(String[] args){
    // ...
    double[][] positionsArray = new double[rowNumber][MAX_POSITION];







share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "196"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Corbin is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216145%2forganize-musicians-into-rows-with-weight-and-population-restrictions%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1












    $begingroup$

    Welcome to code review and thanks for sharing your code.



    Here are some points to consider:





    • declare variables as close to their usage as possible.



      You declared (almost) all your variable at the beginning of your main method which makes it hard to improve your code later on.
      This applies especially to i and j which are used in for loops and should be declared inside them.




    • avoid short variable names.



      Will you remember what tot is in 6 month?




    • do not use the else branch of an if statement as an error handler. Instead of




              while (true) {
      rowLetter = keyboard.next().charAt(0);
      rowLetter = Character.toUpperCase(rowLetter);
      if (rowLetter - 'A' < rowNumber)
      break;
      System.out.print("ERROR: Out of range, try again : ");
      }



      it should be:



              boolean isInputValid = false;
      do {
      rowLetter = keyboard.next().charAt(0);
      rowLetter = Character.toUpperCase(rowLetter);
      isInputValid = (rowLetter - 'A' < rowNumber)
      if (!isInputValid)
      System.out.print("ERROR: Out of range, try again : ");
      } while (!isInputValid);



    • avoid magic numbers



      your code has some literals that need explanation: what is 5 in new double[rowNumber][5];?
      This should be a constant having a meaningful name:



         private static final int MAX_POSITION = 5;
      // ...
      public static void main(String[] args){
      // ...
      double[][] positionsArray = new double[rowNumber][MAX_POSITION];







    share|improve this answer











    $endgroup$


















      1












      $begingroup$

      Welcome to code review and thanks for sharing your code.



      Here are some points to consider:





      • declare variables as close to their usage as possible.



        You declared (almost) all your variable at the beginning of your main method which makes it hard to improve your code later on.
        This applies especially to i and j which are used in for loops and should be declared inside them.




      • avoid short variable names.



        Will you remember what tot is in 6 month?




      • do not use the else branch of an if statement as an error handler. Instead of




                while (true) {
        rowLetter = keyboard.next().charAt(0);
        rowLetter = Character.toUpperCase(rowLetter);
        if (rowLetter - 'A' < rowNumber)
        break;
        System.out.print("ERROR: Out of range, try again : ");
        }



        it should be:



                boolean isInputValid = false;
        do {
        rowLetter = keyboard.next().charAt(0);
        rowLetter = Character.toUpperCase(rowLetter);
        isInputValid = (rowLetter - 'A' < rowNumber)
        if (!isInputValid)
        System.out.print("ERROR: Out of range, try again : ");
        } while (!isInputValid);



      • avoid magic numbers



        your code has some literals that need explanation: what is 5 in new double[rowNumber][5];?
        This should be a constant having a meaningful name:



           private static final int MAX_POSITION = 5;
        // ...
        public static void main(String[] args){
        // ...
        double[][] positionsArray = new double[rowNumber][MAX_POSITION];







      share|improve this answer











      $endgroup$
















        1












        1








        1





        $begingroup$

        Welcome to code review and thanks for sharing your code.



        Here are some points to consider:





        • declare variables as close to their usage as possible.



          You declared (almost) all your variable at the beginning of your main method which makes it hard to improve your code later on.
          This applies especially to i and j which are used in for loops and should be declared inside them.




        • avoid short variable names.



          Will you remember what tot is in 6 month?




        • do not use the else branch of an if statement as an error handler. Instead of




                  while (true) {
          rowLetter = keyboard.next().charAt(0);
          rowLetter = Character.toUpperCase(rowLetter);
          if (rowLetter - 'A' < rowNumber)
          break;
          System.out.print("ERROR: Out of range, try again : ");
          }



          it should be:



                  boolean isInputValid = false;
          do {
          rowLetter = keyboard.next().charAt(0);
          rowLetter = Character.toUpperCase(rowLetter);
          isInputValid = (rowLetter - 'A' < rowNumber)
          if (!isInputValid)
          System.out.print("ERROR: Out of range, try again : ");
          } while (!isInputValid);



        • avoid magic numbers



          your code has some literals that need explanation: what is 5 in new double[rowNumber][5];?
          This should be a constant having a meaningful name:



             private static final int MAX_POSITION = 5;
          // ...
          public static void main(String[] args){
          // ...
          double[][] positionsArray = new double[rowNumber][MAX_POSITION];







        share|improve this answer











        $endgroup$



        Welcome to code review and thanks for sharing your code.



        Here are some points to consider:





        • declare variables as close to their usage as possible.



          You declared (almost) all your variable at the beginning of your main method which makes it hard to improve your code later on.
          This applies especially to i and j which are used in for loops and should be declared inside them.




        • avoid short variable names.



          Will you remember what tot is in 6 month?




        • do not use the else branch of an if statement as an error handler. Instead of




                  while (true) {
          rowLetter = keyboard.next().charAt(0);
          rowLetter = Character.toUpperCase(rowLetter);
          if (rowLetter - 'A' < rowNumber)
          break;
          System.out.print("ERROR: Out of range, try again : ");
          }



          it should be:



                  boolean isInputValid = false;
          do {
          rowLetter = keyboard.next().charAt(0);
          rowLetter = Character.toUpperCase(rowLetter);
          isInputValid = (rowLetter - 'A' < rowNumber)
          if (!isInputValid)
          System.out.print("ERROR: Out of range, try again : ");
          } while (!isInputValid);



        • avoid magic numbers



          your code has some literals that need explanation: what is 5 in new double[rowNumber][5];?
          This should be a constant having a meaningful name:



             private static final int MAX_POSITION = 5;
          // ...
          public static void main(String[] args){
          // ...
          double[][] positionsArray = new double[rowNumber][MAX_POSITION];








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago









        mdfst13

        17.9k62157




        17.9k62157










        answered 18 hours ago









        Timothy TruckleTimothy Truckle

        4,933416




        4,933416






















            Corbin is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Corbin is a new contributor. Be nice, and check out our Code of Conduct.













            Corbin is a new contributor. Be nice, and check out our Code of Conduct.












            Corbin is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216145%2forganize-musicians-into-rows-with-weight-and-population-restrictions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

            How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

            Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...