hello i need help geting my code to work together. when I try and run it inside of the eclipse ide. it says it can't run

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

hello i need help geting my code to work together. when I try and run it inside of the eclipse ide. it says it can't run

Post by answerhappygod »

hello i need help geting my code to work together. when I tryand run it inside of the eclipse ide. it says it can't run due tothe editor not containing a main type. I'm not sure what to do isit a code issue or could it be something wrong with my class files?here is the code
"
package app;
import java.util.Random;
public class DrawingApp {
public static void main(String[] args) {
/*
* For every method remove the line with "throw ..." andimplement the method.
* We are using "throw..." so your code does not displayany compilation errors
* when you import the zip file. Also, if you don'timplement a method you will
* see a white square (instead of green) in the submitserver
*/
public static String getRectangle(int maxRows, intmaxCols, char symbol) {
public class DrawingApp {
public static String getRectangle(intmaxRows, int maxCols, char symbol){
if(maxRows<1 ||maxCols<1){
returnnull;
}
else {
String result= "";
for (int i =0; i < maxRows; i++) {
for (int j = 0; j < maxCols; j++) {
result = result + symbol;
}
result = result + "\n";
}
returnresult;
}
}
public static void main(String[] args){
System.out.print(DrawingApp.getRectangle(6, 9, '*'));
}
}
public static void main(String[] args){
System.out.println(DrawingApp.getFlag(9, 'R', '.', 'Y'));//invoking the getFlag method
}
public static String getFlag(int size,char color1, char color2, char color3) {
//if the size < 3, thenreturn null
if (size <3)
returnnull;
//if size more than2
StringBuilder builder = newStringBuilder(""); //output string builder
//main loop, for no:of rows(size x 2)
for(int i=1; i <= (size *2); i++) {
//sub loop,for no:of columns (size x 5)
for(int j=1; j<= (size * 5); j++) {
//for first & last lines
if(i==1 || i== (size * 2)) {
if(j==1) //for firstcharacter
builder.append(color1);
else //for all other characters in first& last line
builder.append(color2);
}else if( i == size || i == (size + 1)) { //for the middle 2lines
if(j <= size) //if column is less thansize
builder.append(color1);
else //for all other columnvalues
builder.append(color2);
}else { //for all other rows other than first, last and middle 2lines
if(i <= size) { //for the first part
if (j <= i)
builder.append(color1);
else
builder.append(color3);
}else { //for second part
if (j <= (size - (i % (size +1))))
builder.append(color1);
else
builder.append(color3);
}
}
}
builder.append("\n"); //for each new row
}
returnbuilder.toString(); //return the string
}
//
public static String getHorizontalBars(int maxRows, intmaxCols, int bars, char color1, char color2, charcolor3){
int rows = maxRows/bars;
String result = "";
for(int j = 0;j<bars;j++){
for (int i = 0; i < rows;i++) {
for (int k =0; k < maxCols; k++) {
if (j % 3 == 0) {
result += color1;
} else if (j % 3 == 1) {
result += color2;
} else {
result += color3;
}
}
result +="\n";
}
}
return result;
}
//
public static String getVerticalBars(int maxRows, intmaxCols, int bars, char color1, char color2, charcolor3){
char[] colors = new char[3];
colors[0] = color1;
colors[1] = color2;
colors[2] = color3;
int currentColorIndex = 0;
char currentColor = colors[0];
int sizeOfBar = maxCols/bars;
String str = "";
String ans = "";
for(int i=0;i<maxCols;i++){
str += currentColor;
if(i%sizeOfBar==sizeOfBar-1){
currentColorIndex =(currentColorIndex+1)%3;
currentColor = colors[currentColorIndex];
}
}
for(int j=0;j<maxRows;j++){
ans += str;
ans += "\n";
}
return ans;
}
public static void main(String[] args) {
System.out.println(getVerticalBars(10,12,3,'R','G','B'));
System.out.println(getVerticalBars(5,12,4,'R','G','B'));
System.out.println(getVerticalBars(5,20,5,'R','G','B'));
}
}
//
public static char getRandomColor(Random random){
int choice =random.nextInt(6);
if (choice == 0){
return'R';
} else if (choice == 1){
return'G';
} else if (choice == 2){
return'B';
} else if (choice == 3){
return'Y';
} else if (choice == 4){
return'*';
} else {
return'.';
}
}
public static void main(String[] args){
Random random = newRandom();
System.out.println("Randomcolor: " + getRandomColor(random));
System.out.println("Randomcolor: " + getRandomColor(random));
System.out.println("Randomcolor: " + getRandomColor(random));
System.out.println("Randomcolor: " + getRandomColor(random));
}
}
}
//
private static boolean isValidColor(char color){
if (color == 'R' || color == 'G' || color== 'B'|| color == 'Y' || color == '*' || color == '.'){
return true;
} else {
return false;
}
}
}
}
}
"
any and all help is appreciated thankyou
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply