Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Use the Integer wrapper class.
Declare and use ArrayList class objects.
Write code to read from, and write to, text files.
Write an exception handler for an I/O exception.
Write Java classes and instantiate objects of those classes.
3 Background
Let list be a nonempty sequence of nonnegative random integers, each in the range [0, 32767] and let n be the length of list, e.g.,
list = { 2, 8, 3, 2, 9, 8, 6, 3, 4, 6, 1, 9 }
where n = 12. List elements are numbered starting at 0. We define a run up to be a (k+1)-length subsequence listi, listi+1, listi+2, ..., listi+k, that is monotonically increasing (i.e., listi+j ≥ listi+j-1 for each j = 1, 2, 3, ..., k). Similarly, a run down is a (k+1)-length subsequence listi, listi+1, listi+2, ..., listi+k, that is monotonically decreasing (i.e., listi+j-1 ≤ listi+j for each j = 1, 2, 3, ..., k). For the above example list we have these runs up and runs down:
Runs Up
list0 throughlist1 ={2,8};k=1 list2 ={3};k=0
list3 throughlist4 ={2,9};k=1 list5 ={8};k=0
list6 ={6};k=0
list7 throughlist9 ={3,4,6};k=2 list10 throughlist11 ={1,9};k=1
Runs Down
list0 ={2};k=0
list1 throughlist3 ={8,3,2};k=2 list4 throughlist7 ={9,8,6,3};k=3 list8 ={4};k=0
list9 throughlist10 ={6,1};k=1 list11 ={9};k=0
We are interested in the value of k for each run up and run down and in particular we are interested in the total umber of runs for each nonzero k, which we shall denote by runsk, 0 < k < n - 1. For the example list we have:
k runsk runs
1 4 {2,8},{2,9},{1,9},and{6,1}
2 2 {3,4,6,}and{8,3,2}
3 1 {9,8,6,3}
4-11 0
Letrunstotal bethethesumfromk=1ton-1ofrunsk.Fortheexamplelist,runstotal =4+2+1=7.
Arizona State University
Page 1

CSE205 Object Oriented Programming and Data Structures Programming Project 1 :: 25 pts
4 Software Requirements
Your program shall:
Open a file named p01-in.txt containing n integers, 1 ≤ n ≤ 1000, with each integer in [0, 32767]. There will be one or more integers per line. A sample input file: Sample p01-in.txt 283
29
8 6 34619
The program shall compute runsk for k = 1, 2, 3, ..., n - 1.
The program shall compute runstotal.
The program shall produce an output file named p01-runs.txt containing runstotal and runsk for k = 1, 2, 3, ..., n - 1. The file shall be formatted as shown in the example file below. Sample p01-runs.txt runs_total, 7
runs_1, 4
runs_2, 2
runs_3, 1
runs_4, 0
runs_5, 0
runs_6, 0
If the input file p01-in.txt cannot be opened for reading (because it does not exist) then display an error message on the output window and immediately terminate the program, e.g., run program...
Sorry, could not open 'p01-in.txt' for reading. Stopping.
5 Software Design
Your program shall:
Contain a class named Main. This class shall contain the main() method. The main() method shall instantiate an object of the Main class and call run() on that object.
// Main.java
public class Main {
public static void main(String[] pArgs) {
Main mainObject = new Main();
mainObject.run()
}
private void run() {
// You will start writing code here to implement the software requirements.
}
}
One of the primary objectives of this programming project is to learn to use the java.util.ArrayList class. Therefore, you are not permitted to use 1D arrays. Besides, you will quickly discover that the ArrayList class is more convenient to use than 1D arrays.
Arizona State University Page 2

CSE205 Object Oriented Programming and Data Structures Programming Project 1 :: 25 pts
ArrayList is a generic class meaning: (1) that it can store objects of any class; and (2) when an ArrayList object is declared and instantiated we must specify the class of the objects that will be stored in the ArrayList. For this project, you need to define an ArrayList that stores integers, but you cannot specify that your ArrayList stores ints because int is a primitive data type and not a class. Therefore, you will need to use the java.lang.Integer wrapper class:
ArrayList list = new ArrayList<>():
int x = 1;
list.add(x); // Legal because of Java autoboxing.
You must write an exception handler that will catch the FileNotFoundException that gets thrown when the input file does not exist (make sure to test this). The exception handler will print the friendly error message and immediately terminate the Java program. To immediately terminate a Java program we call a static method named exit() which is in the java.lang.System class. The exit() method expects an int argument. For this project, it does not matter what int argument we send to exit(). Therefore, terminate the program this way: try {
// Try to open input file for reading
} catch (FileNotFoundException pExcept) {
// Print friendly error message
System.exit(-1);
}
Your programming skills should be sufficiently developed that you are beyond writing the entire code for a program in one method. Divide the program into multiple methods. Remember, a method should have one purpose, i.e., it should do one thing. If you find a method is becoming complicated because you are trying to make that method do more than one thing, then divided the method into 2, 3, 4, or more distinct methods, each of which does one thing.

Avoid making every variable or object an instance variable. For this project you shall not declare any instance variables in the class. That is, all variables should be declared as local variables in methods and passed as arguments to other methods when appropriate.

Format your code neatly. Use proper indentation and spacing. Study the examples in the book and the examples the instructor presents in the lectures and posts on the course website.

Java, Programming

  • Category:- Java
  • Reference No.:- M92400306
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As