Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to run a project in netbeans and I keep getting the error that my main class is not found. I copied my code

I'm trying to run a project in netbeans and I keep getting the error that my main class is not found. I copied my code below:

package mryan26;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

new Main().run();

}

public void run() {

ArrayList list = new ArrayList();

Scanner fileInput = null;

try {

fileInput = new Scanner(new File("p01-in.txt"));

} catch (FileNotFoundException e) {

System.out.println("Sorry, file can not be found");

System.exit(-1);

}

while (fileInput.hasNextInt()) {

list.add(fileInput.nextInt());

}

ArrayList listRunsUpCount = new ArrayList();

ArrayList listRunsDnCount = new ArrayList();

listRunsUpCount = FindRuns(list, 0);

listRunsDnCount = FindRuns(list, 1);

ArrayList listRunsCount = new ArrayList();

listRunsCount = mergeLists(listRunsUpCount, listRunsDnCount);

writeOutputFile("p01-runs.txt", listRunsCount);

}

public ArrayList FindRuns(ArrayList pList, int pDir) {

ArrayList listRunsCount = arrayListCreate(pList.size(), 0);

int i = 0, k = 0;

while (i < pList.size() - 1) {

if (pDir == 0 && pList.get(i) <= pList.get(i + 1)) {

k++;

} else if (pDir == 1 && pList.get(i) >= pList.get(i + 1)) {

k++;

} else {

if (k != 0) {

listRunsCount.set(k, listRunsCount.get(k) + 1);

k = 0;

}

}

i++;

}

if (k != 0) {

listRunsCount.set(k, listRunsCount.get(k) + 1);

}

return listRunsCount;

}

public ArrayList mergeLists(ArrayList pListRunsUpCount, ArrayList pListRunsDnCount) {

ArrayList listRunsCount = arrayListCreate(pListRunsUpCount.size, 0);

for (int i = 0; i < pListRunsUpCount.size() - 1; i++) {

listRunsCount.set(i, pListRunsUpCount.get(i) + pListRunsDnCount.get(i));

}

return listRunsCount;

}

public ArrayList arrayListCreate(int pSize, int pInitValue) {

ArrayList list = new ArrayList();

for (int i = 0; i < pSize; i++) {

list.add(pInitValue);

}

return list;

}

public void writeOutputFile(String pFileName, ArrayList pListRuns) {

PrintWriter out = null;

try {

out = new PrintWriter(new File(pFileName));

} catch (FileNotFoundException e) {

System.out.println("Sorry file not found");

System.exit(-1);

}

int totalRuns = 0;

for (int i = 0; i < pListRuns.size(); i++) {

totalRuns += pListRuns.get(i);

}

out.print("runs_total, " + totalRuns);

for (int k = 1; k < pListRuns.size() - 1; k++) {

out.print("runs_" + k + "," + pListRuns.get(k));

}

out.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago