首页 > > 详细

Java辅导CS2230 Computer Science 辅导Java设计、Java编程辅导


Introduction
Requirement
CS2230 Computer Science II: Data
Structures
Homework 1
Intro to Java
Due January 26, 2016, 11:59pm
Goals for this assignment
• Make sure you can run the NetBeans IDE
• Gain some familiarity with Java syntax
• Use Java to solve some problems
Submission Checklist
You should submit the two .java files specified in Part 2 of this document. Upload them on ICON
under Assignments > Homework 1. Physical paper copies are not accepted.
• Does AbsMax.java run as required?
• Does TwoSum.java run as required?
• Did you submit both files to ICON?
Part 1: Run NetBeans
Option 1: run NetBeans in the computing lab
The lab machines in 301 MLH have NetBeans installed. Open it from the start menu.
Option 2: run NetBeans on your own computer
Download the JDK with NetBeans package. To do so, you must accept the license agreement
and then click the link for your platform.
(If by chance you already have JDK 8 installed, then you may install just NetBeans, pick Java SE).
More detailed instructions:
Now you may either use the official tutorial, or the one we’ve included below.
a) Once NetBeans is running, go to New Project.
or
b) Then pick the appropriate options
c) On the next screen, give your Project a name. Let’s call it Example.
d) After click Finish, you should see the editor on the right, and your Project files on the
left.
e) Let’s create a new Java class. Right click the brown package called examples.
f) Call your class Integration
g) Copy in the code from lecture
h) We need to tell NetBeans the name of the class whose main() method we want to run,
as well as provide the 3 command line arguments.
Edit the configuration. In particular, the Main Class and the Arguments.
i) Now run!
You should see some output in the console on the bottom of the screen.
Try making tweaks to the program or to the Arguments to make sure you understand the
example.
j) Now you are ready to make your own classes and run them!
Part 2
Problem 1 (10 points)
Write a method abs_max that takes an array as an argument and returns the integer with the
maximum absolute value. In the case of ties, take the integer that appears earliest in the array.
Here are some example cases.
[1,2,5,3,4] => 5
[-1, 0, 1] => -1
[1, 0, -1] => 1
[3, -1, 5, -6] => -6
Implement your solution in the file we have provided: AbsMax.java. Your program should run
and print only “Tests pass” in the console. It is your responsibility to make sure the program
runs properly either in NetBeans OR with the following command line commands.
javac AbsMax.java
java AbsMax
Problem 2 (10 points)
Write a method two_sum that takes an array as an argument and returns true if the array
contains at least one pair of different elements that add up to 0 and returns false otherwise.
Here are some example cases.
[-1,-2,-2,4] => false
[1,2,3,4,0] => false
[0, 5, 0, -1, 10, 11] => true
[-4, 5, -6, 7, 4, 3] => true
[1, 2, -1, -2] => true
Implement your solution in the file we have provided: TwoSum.java. Your program should run
and print only “Tests pass” in the console. It is your responsibility to make sure the program
runs properly either in NetBeans OR with the following command line commands.
javac TwoSum.java
java TwoSum
Helpful Tips
• What do I do if my program prints the following?
FAILED TEST 1a
This message means that your method didn’t return the correct answer for the test 1a. You
must debug your program. Go look at TEST 1a in the main() method and make sure you
understand the test case. Try adding print statements (System.out.prinln(…)) to different parts
of your code to see what values variables have at different times to see if it is what you
expected.

 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!