SlideShare a Scribd company logo
I can not get my code to comply it gets mad that I have run declare more than once. Please help
me figure out how to get this to work
package projectOne;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
import java.io.*;
public class Main
{ public static void main(String[] pArgs){
Main mainObject = new Main();
mainObject.run();
} private void run() {
public FileReader readFile() throws FileNotFoundException {
FileReader file = new FileReader("p01-in.txt");
return file;
}
public ArrayList<Integer> getData(FileReader file) throws FileNotFoundException {
Scanner data_read = new Scanner(new BufferedReader(file));
ArrayList<Integer> data = new ArrayList<Integer>();
while (data_read.hasNext()) {
int item = data_read.nextInt();
data.add(item);
}
return data;
}
public ArrayList<Integer> calcRuns(ArrayList<Integer> data) {
ArrayList<Integer> runs = new ArrayList<Integer>();
Iterator<Integer> i_data = data.iterator();
int run = 0;
int temp = i_data.next();
while (i_data.hasNext()) {
int t1 = i_data.next();
if (temp < t1)
run++;
else {
runs.add(run);
run = 0;
}
temp = t1;
}
i_data = data.iterator();
temp = i_data.next();
run = 0;
while (i_data.hasNext()) {
int t1 = i_data.next();
if (temp > t1)
run++;
else {
runs.add(run);
run = 0;
}
temp = t1;
}
return runs;
}
public void writeOutput(ArrayList<Integer> runs) throws IOException {
PrintWriter out = new PrintWriter(new File("p01-runs.txt"));
ArrayList<Integer> run_count = new ArrayList<Integer>();
int i = 0;
int r_count = Collections.frequency(run_count, i);
while (i < 100) {
run_count.add(r_count);
i++;
r_count = Collections.frequency(runs, i);
}
Iterator<Integer> i_runs = run_count.iterator();
i = 0;
while (i_runs.hasNext()) {
int run = i_runs.next();
String line = "run_" + i + " ," + run;
i++;
out.println(line);
}
}
public void run() throws Exception {
FileReader fin = this.readFile();
ArrayList<Integer> data = this.getData(fin);
ArrayList<Integer> runs = this.calcRuns(data);
this.writeOutput(runs);
}
}
Solution
In your program you have to change the syntax errors at method declaration.so your not getting
output.

More Related Content

DOCX
DOCX
Code red SUM
PDF
Important java programs(collection+file)
PDF
i am finishing a project for my cs 0401 java course. I have complete.pdf
PDF
Java Programming Must implement a storage manager that main.pdf
PDF
Java Programming In this programming assignment, you need to impl.pdf
DOCX
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PPTX
File Handling.pptx
Code red SUM
Important java programs(collection+file)
i am finishing a project for my cs 0401 java course. I have complete.pdf
Java Programming Must implement a storage manager that main.pdf
Java Programming In this programming assignment, you need to impl.pdf
PAGE 1Input output for a file tutorialStreams and File IOI.docx
File Handling.pptx

Similar to I can not get my code to comply it gets mad that I have run declare mo.docx (20)

PDF
The Java Program for the above given isimport java.io.File;impo.pdf
PDF
Active Software Documentation using Soul and IntensiVE
PDF
Android Studio Assignment HelpCan someone who is familiar with And.pdf
PDF
Please I am trying to get this code to output in -txt file- I need you.pdf
PDF
DisplayBook.java import java.io.File; import java.io.FileInput.pdf
PDF
54240326 (1)
PDF
54240326 copy
PDF
Writing Swift code with great testability
PDF
Change the code in Writer.java only to get it working. Must contain .pdf
PDF
I am sorry but my major does not cover programming in depth (ICT) an.pdf
DOCX
JAVA Q2- Write a program that reads strings from the user and writes t.docx
PDF
2. Write a program which will open an input file and write to an out.pdf
DOCX
Know how to redirect input and output- and know how to append to an ex.docx
PPTX
ExtraFileIO.pptx
PPSX
PDF
DOCX
import org-jsoup-Jsoup- import org-jsoup-nodes-Document- import java-.docx
PPTX
Understanding java streams
PPT
Java Serialization
PPTX
Session 23 - JDBC
The Java Program for the above given isimport java.io.File;impo.pdf
Active Software Documentation using Soul and IntensiVE
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Please I am trying to get this code to output in -txt file- I need you.pdf
DisplayBook.java import java.io.File; import java.io.FileInput.pdf
54240326 (1)
54240326 copy
Writing Swift code with great testability
Change the code in Writer.java only to get it working. Must contain .pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
JAVA Q2- Write a program that reads strings from the user and writes t.docx
2. Write a program which will open an input file and write to an out.pdf
Know how to redirect input and output- and know how to append to an ex.docx
ExtraFileIO.pptx
import org-jsoup-Jsoup- import org-jsoup-nodes-Document- import java-.docx
Understanding java streams
Java Serialization
Session 23 - JDBC
Ad

More from hamblymarta (20)

DOCX
Choose a piece of children's-adolescent media from any era and analyze.docx
DOCX
Complete parts (a) and (b) below- The number of dogs per household in.docx
DOCX
Comider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docx
DOCX
Combining estimates with projections of likely events such as turnover.docx
DOCX
Christine Danes has asked Dave and Mike to help her move into a new ap.docx
DOCX
Cody is trying to explain to Sarah that one advantage enjoyed by plant.docx
DOCX
Combining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docx
DOCX
Code needed in C++ Input and formatted output- Right-facing arrow Give.docx
DOCX
Class problem 5 -Animal personality- has been defined as consistent di.docx
DOCX
Class Discussion - Guest Speaker - Laura Sonderup Q1- From your exper.docx
DOCX
Choose all that apply- Which of the following proteins would have an E.docx
DOCX
Choose all that apply- Which of the following is something that all ce.docx
DOCX
Choose every statement that is true about the cytoplasm- Cytoplasm can.docx
DOCX
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
DOCX
Charles Darwin used many different aspects of the natural world as evi.docx
DOCX
Chapter 2 notes various problems in the use of ratios and metrics- Whi.docx
DOCX
Case -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docx
DOCX
care plannursing diagnose risk for evidenced by prostatis nursing dia.docx
DOCX
Can you please help me answer these two multiple choice questions- Tha.docx
DOCX
can someome please write the init method please This interface defines.docx
Choose a piece of children's-adolescent media from any era and analyze.docx
Complete parts (a) and (b) below- The number of dogs per household in.docx
Comider a pond or tiver adfacent to a higpo iawn in Arrica- The water.docx
Combining estimates with projections of likely events such as turnover.docx
Christine Danes has asked Dave and Mike to help her move into a new ap.docx
Cody is trying to explain to Sarah that one advantage enjoyed by plant.docx
Combining Prehension and Propulsion- The Foot of Ardipithecus ramidus.docx
Code needed in C++ Input and formatted output- Right-facing arrow Give.docx
Class problem 5 -Animal personality- has been defined as consistent di.docx
Class Discussion - Guest Speaker - Laura Sonderup Q1- From your exper.docx
Choose all that apply- Which of the following proteins would have an E.docx
Choose all that apply- Which of the following is something that all ce.docx
Choose every statement that is true about the cytoplasm- Cytoplasm can.docx
Case Study- Data-Driven Transformation of Springfield's Police Force S.docx
Charles Darwin used many different aspects of the natural world as evi.docx
Chapter 2 notes various problems in the use of ratios and metrics- Whi.docx
Case -#2- Royal Bank of Canada v- Head West Energy Inc-- 2007 ABQB 154.docx
care plannursing diagnose risk for evidenced by prostatis nursing dia.docx
Can you please help me answer these two multiple choice questions- Tha.docx
can someome please write the init method please This interface defines.docx
Ad

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Cell Structure & Organelles in detailed.
PDF
Computing-Curriculum for Schools in Ghana
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
01-Introduction-to-Information-Management.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPH.pptx obstetrics and gynecology in nursing
Cell Structure & Organelles in detailed.
Computing-Curriculum for Schools in Ghana
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
01-Introduction-to-Information-Management.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

I can not get my code to comply it gets mad that I have run declare mo.docx

  • 1. I can not get my code to comply it gets mad that I have run declare more than once. Please help me figure out how to get this to work package projectOne; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.*; import java.io.*; public class Main { public static void main(String[] pArgs){ Main mainObject = new Main(); mainObject.run(); } private void run() { public FileReader readFile() throws FileNotFoundException { FileReader file = new FileReader("p01-in.txt"); return file; } public ArrayList<Integer> getData(FileReader file) throws FileNotFoundException { Scanner data_read = new Scanner(new BufferedReader(file)); ArrayList<Integer> data = new ArrayList<Integer>(); while (data_read.hasNext()) { int item = data_read.nextInt(); data.add(item); } return data; } public ArrayList<Integer> calcRuns(ArrayList<Integer> data) { ArrayList<Integer> runs = new ArrayList<Integer>(); Iterator<Integer> i_data = data.iterator(); int run = 0; int temp = i_data.next(); while (i_data.hasNext()) { int t1 = i_data.next(); if (temp < t1) run++; else { runs.add(run); run = 0; } temp = t1; } i_data = data.iterator();
  • 2. temp = i_data.next(); run = 0; while (i_data.hasNext()) { int t1 = i_data.next(); if (temp > t1) run++; else { runs.add(run); run = 0; } temp = t1; } return runs; } public void writeOutput(ArrayList<Integer> runs) throws IOException { PrintWriter out = new PrintWriter(new File("p01-runs.txt")); ArrayList<Integer> run_count = new ArrayList<Integer>(); int i = 0; int r_count = Collections.frequency(run_count, i); while (i < 100) { run_count.add(r_count); i++; r_count = Collections.frequency(runs, i); } Iterator<Integer> i_runs = run_count.iterator(); i = 0; while (i_runs.hasNext()) { int run = i_runs.next(); String line = "run_" + i + " ," + run; i++; out.println(line); } } public void run() throws Exception { FileReader fin = this.readFile(); ArrayList<Integer> data = this.getData(fin); ArrayList<Integer> runs = this.calcRuns(data); this.writeOutput(runs); } }
  • 3. Solution In your program you have to change the syntax errors at method declaration.so your not getting output.