Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS 2334: Lab 1
Andrew H. Fagg: CS2334: Lab 1 1
Hello, my name is ________
Andrew H. Fagg: CS2334: Lab 1 2
General Procedures
• Most labs will have a short lecture component
• May “follow along” with Eclipse
• You are welcome to “run ahead” on the lab itself, but please do 
not disrupt the lecture
• The lecture will be followed by time to work on the assigned 
lab and interact one-on-one with the TAs
Andrew H. Fagg: CS2334: Lab 1 3
General Procedures
• The labs are designed to be largely completed in the lab 
session
• Perhaps with a bit of clean-up afterwards
• If you finish early and the TA has a chance to do some 
preliminary testing, then you may leave the session early
Andrew H. Fagg: CS2334: Lab 1 4
Download and Install
• Java JDK:
http://www.oracle.com/technetwork/java/javase/dow
nloads/jdk8-downloads-2133151.html
• Eclipse:
http://www.eclipse.org/downloads
• Both (Windows only):
https://ninite.com/
Andrew H. Fagg: CS2334: Lab 1 5
Web-CAT Setup and Install
• Configuring Eclipse
http://www.cs.ou.edu/~fagg/classes/cs2334/webcat.html
Andrew H. Fagg: CS2334: Lab 1 6
Task 1
• Create a new project called Lab1
• Create a class called Driver
• The main method prints “Hello, World!”
• Compile and execute
(demo: Eclipse)
Andrew H. Fagg: CS2334: Lab 1 7
Task 2
Create a new class: Planning
• One property, called info that is an array of 4 Strings
• One constructor method:
public Planning(String strg)
where strg is “,, is a string
 and  are strings encoding positive integers
Andrew H. Fagg: CS2334: Lab 1 8
Task 2
Create a new class: Planning
public Planning(String strg)
• The constructor method splits the string into three parts and fills 
in the info property:
info[0] is the  in all upper case
info[1] is the number of  enrolled
info[2] is the  class size
info[3] is the number of sections needed for the enrollment
(demo: Java API: Strings)
Andrew H. Fagg: CS2334: Lab 1 9
Task 2
Planning:
• toString() method:
public String toString()
• Describe the Planning object
• Constructor string: “Java,153,50”
• toString()  output:
CLASS: JAVA, Enrolled: 153, Max class size: 50, Sections: 4
Andrew H. Fagg: CS2334: Lab 1 10
Project-Level Documentation
Include at the top of every file:
/**
@author 
@version 
Lab: 

*/
Andrew H. Fagg: CS2334: Lab 1 11
Method-Level Documentation
How should we document the following method?
public static boolean isInRange(double min, double max, double value)
Andrew H. Fagg: CS2334: Lab 1 12
Method-Level Documentation
/**
Indicate whether a value is within a range of values
@param min Minimum value in the range
@param max Maximum value in the range
@param value The value being tested
@return True if value is between min and max.  False if outside this
range.
*/
public static boolean isInRange(double min, double max, double value)
Andrew H. Fagg: CS2334: Lab 1 13
Inline Documentation
• Include inline documentation for each line of code, or small 
group of lines
• Capture the logic of what is happening (and why) – don’t 
repeat what the code says
Andrew H. Fagg: CS2334: Lab 1 14
Inline Documentation
public static boolean isInRange(double min, double max, double value)
{
// Check lower bound
if (value < min)
{
return false;
}
// Check upper bound
if (value > max) 
{
return false;
}
// Within the boundaries
return true;
}
Andrew H. Fagg: CS2334: Lab 1 15
Back to Task 2 …
Replace your Driver class main function:
public static void main(String [] args) throws IOException
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
String input = br.readLine();
// Fill in 2 lines of code here
br.close();
}
Add code:
• Use input to create an instance of Planning
• Print Planning instance
Andrew H. Fagg: CS2334: Lab 1 16
Testing 
(some examples)
Input in console: ”Java,153,50” 
Output:
CLASS: JAVA, Enrolled: 153, Max class size: 50, Sections: 4
Input: “ai,35,40”
Output:
CLASS: AI, Enrolled: 35, Max class size: 40, Sections: 1
Andrew H. Fagg: CS2334: Lab 1 17
Generate Documentation with Javadoc
(demonstration)
Notes: 
• Use private visibility
• Use the default destination
• You should check your documentation to make sure 
everything was included.
Andrew H. Fagg: CS2334: Lab 1 18
Submitting to Web-CAT
(demonstration)
Notes:
• Make sure that the correct project is selected.
Andrew H. Fagg: CS2334: Lab 1 19
Submission
• Due date: Friday, August 26th @11:59pm
• Use the Lab 01 (2334): Planning assignment
• Multiple submissions are allowed (but don’t abuse this)
Andrew H. Fagg: CS2334: Lab 1 20