找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1051|回复: 20

谁会JAVA编程

[复制链接]
发表于 2007-5-9 13:27:08 | 显示全部楼层 |阅读模式
救急 " a+ ^7 a: p" s 9 V' j' R2 Z1 g% O6 z0 [* H3 {8 ^
回复

使用道具 举报

 楼主| 发表于 2007-5-9 13:57:40 | 显示全部楼层
没人懂吗?
回复

使用道具 举报

发表于 2007-5-9 13:58:19 | 显示全部楼层
偶懂一点点点
回复

使用道具 举报

 楼主| 发表于 2007-5-9 13:58:55 | 显示全部楼层
我在做作业啊...遇到不会的问下你..
回复

使用道具 举报

发表于 2007-5-9 14:00:01 | 显示全部楼层
还给老师了
回复

使用道具 举报

发表于 2007-5-9 14:00:25 | 显示全部楼层
我晕到,做JAVA的作业啊  ,你学啥子的
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:00:46 | 显示全部楼层
问下,如果有两个.java的文件,这两个文件有相似性...我们的要求是写一个另外的java程序,然后可以载如 这两个java文件,进行code的逐行对比,然后列出相似的行和相似内容,应该用什么类
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:11 | 显示全部楼层
//*********************************************************************
4 }) _0 a% {5 T  D0 h//  ProgramCompare.java         Provided by: DRS
  I4 g7 c+ F8 I, y$ w//
2 U: h! G# k; K//  Program shell for Assignment 2
6 q$ j2 r  u- K) G. J//' H. C4 [8 `% W1 m
//  Compares two text files line by line
1 `/ X4 y; E# \  \- U+ [# L) o. Q9 I. t//*********************************************************************
: s5 I5 v/ J% ?9 D3 j6 M6 v% q4 c3 W
import java.io.*;* M3 p! Y: j5 \6 F: |: G! E4 C

1 s, W/ b+ v- z# A+ C  Bpublic class ProgramCompare
7 Q8 x$ g6 G1 {! P{: V4 }- h3 P7 b: f- s( E
        //-----------------------------------------------------------------
4 {9 r4 ]& [( K' X! t, g; {        // Constructor
/ D; F" ~! C, ]: @" I# A- S7 W        //-----------------------------------------------------------------, j7 j' V+ L: m0 D- k
        public ProgramCompare()
, V# e# t0 ]0 C) U1 b3 r$ q        {
' H. l; W4 ]7 s5 j& K9 A        }
# d7 r, g6 H. B9 {6 r* K, q0 [! ?5 [$ I7 u' J- G: ~  k2 H
        //-----------------------------------------------------------------% c% z- k0 d& e: o# @
        // Method for testing that class has been reached
/ }7 b6 _. T! e* P/ c        //-----------------------------------------------------------------        # A, M0 ^6 }) z9 n& S6 H: ~$ Y

2 M$ D! O$ H$ A* T1 p        public boolean ProgramCompareReached()         ! h& s" j7 J: j" M( ?
        {
+ d6 Q/ ?7 s$ \; a) @; _0 D      try
4 \# m+ f/ D. d( g: m( E   {         1 @6 x1 v! i5 z8 s& s
                       
/ _" d6 j$ N5 [- F% r# ~* l4 X                //********************************************************************
( Y! G' N: }! |' D7 Y6 e, n  K                // Try-Catch Statement is used to handle exceptions - such as file not found
8 A. J! G3 @. U. B. c                // Reading the files will need to be placed inside a Try-Catch - just like this one!
7 Y& b5 @. x9 I# ~                // For more information see page 534 of the textbook
5 ~* Q5 E3 e' z6 g9 B7 F0 a6 k( W                //********************************************************************
2 w, N, z" B4 a! P; k. g                    
( f: ]6 Y' _! E" j  ^7 C        }
4 ~* K5 n8 |: t6 ]- c             catch (Exception ex) // Exception caught here and message displayed to the screen
" e$ S) d# f3 D7 b/ Y          {
3 a9 l- d3 m" C2 a  ~                    ex.printStackTrace (System.err);( ~% ?- f% w! E# y) T. [  l: w4 E. _
           System.out.println ("Error message goes here"); // Replace this error message with your own         
9 T9 q% H* @, H, [1 E' g4 ]        }
2 j3 P$ _3 ^) s( S* z                return true;9 v& g6 D) J* O% f: }  e: E2 d
        }5 S1 t. |  Z# W' a. Y/ |- k
8 N7 a: E& Q9 p7 w0 R7 y6 h3 _
} // end of class ProgramCompare
5 Q  B( T$ e$ b; o. m5 X) y' S& T, l0 W7 l6 f
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:41 | 显示全部楼层
//********************************************************************* Y1 x$ g& t) W8 ~: k, \
//  ProgramCompareMenu.java    Provided by: DRS
' _9 K# f& W" A//4 _5 J7 `+ t- z/ ~& p& i
//  Calls AuthorisedUsers.java and ProgramCompare.java3 a4 S+ j5 X1 E6 j9 V2 Z+ ~
//% N/ s* t% g+ B
//  Driver shell for Assignment 2.
3 }# G& \) _" N' x2 ~9 a. u//********************************************************************: d9 e3 a7 ?; \& o
. l$ N" v6 Z' U. N  P% z' K7 k
class ProgramCompareMenu7 i) t/ }7 ]2 A, x" B% y
{  x- P" ]; ~5 }- q
    public static void main (String[] args)
; k" b4 a! J$ B0 p# A            {
, c1 D4 n; |9 T. j) q. z                //Check that the two classes ProgramCompare and AuthorisedUsers are reachable8 W& x/ R3 C, m
                ProgramCompare reached1 = new ProgramCompare(); 8 s- q8 Q1 R: Y2 d# @, D9 \
                AuthorisedUsers reached2 = new AuthorisedUsers();          D. h" {$ m4 f; r/ u
                System.out.println("ProgramCompare reached? " + reached1.ProgramCompareReached());
% Y0 l8 k6 o7 s  z3 `) V1 B                System.out.println("AuthorisedUsers reached? " + reached2.AuthorisedUsersReached());        - O# V' s  d: p" F3 I( e+ Y
        }
& N) p$ i' c* o8 i% I}// end of class ProgramCompareMenu
1 |9 m% e0 F( c9 ?. k+ k2 S+ s- g) S4 L. K
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:55 | 显示全部楼层
//********************************************************************) A! M. ~' f+ S1 s. C( l- P0 N& s
//          AuthorisedUsers.java          Provided by: DRS
0 A; w# Q9 `9 Q2 q//               
- v7 _: B- J0 I; {3 H//         Program shell for Assignment 2! r0 O) I1 Q+ k& Y
//0 A% i' A4 R" c1 }) {, e
//         Represents facts about an AuthorisedUser
# l+ n% u% l1 R" l% z# P2 E' G//********************************************************************
( E1 y. C2 B# H. R9 K
: V/ C' Z4 j0 G, C" r( i2 H7 ypublic class AuthorisedUsers
( E$ I& h, z% j8 x    {8 ?% z* J* }5 q( P4 q6 q
0 c1 l0 g( G' O/ [, K
        //-----------------------------------------------------------------
$ O# G, [+ n1 h9 @) z+ b        // Constructor
( R& _, |: ]) S        //-----------------------------------------------------------------
' z) S# }" s# P3 G3 o6 P. O
& r1 N4 g3 B! ]$ b# l        public AuthorisedUsers()  J  W8 E! j' n( y
                {. g5 o6 ~7 |" ~/ H
                }& s4 H- a) t# B! Q$ Z: |! \# A

' P0 N' Q& j6 Z7 G) `; V. Z6 {        //-----------------------------------------------------------------, O" x' v0 m' e
        // Method for testing that class has been reached/ ~( |6 V* z  U9 t% _2 z: C( j
        //-----------------------------------------------------------------        4 r+ F2 ?8 }, V& ^  Y: }9 s3 Y
        public boolean AuthorisedUsersReached()
) P" \9 S, i& k3 R" i2 Q                {; C& A/ S* @0 k' Z' P
                        return true;                       
7 [. \% v4 a- a( o: p                }' K' |3 z; }, N0 a( ]
                & Q6 a- y9 C! d1 \8 Z/ A. d5 j
    } // end of class AuthorisedUsers
3 _; E9 w3 t' C. K; q//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:32 | 显示全部楼层
BSA104 Business Programming: ]- j8 i% K9 j: q1 s  w" x
Shanghai - 2007' `% E% a, B* j% j
Assignment 2
. M$ N3 s( R/ U1 M9 RDeadline for Submission: 10:00 pm (Shanghai time), Tuesday 15th May 2007 Assessment Weighting: 20% of the total assessment for BSA104 Assignment Type: Individual Scenario: The teaching staff at a nearby university are concerned that some of their students are submitting other students‟ work. They need a simple Java program that will compare the text of two other Java programs, line by line, for equality, and then print out the results, and a recommendation. Requirements: Consider the three Java Classes: ProgramCompareMenu.java, ProgramCompare.java and AuthorisedUsers.java, available from the Assignment 2 page on Vista. You are required to perform the following tasks: The ProgramCompareMenu class: (Total maximum 20 marks available)6 y* K5 q" i" v& e
1. Provide a basic text-based menu interface to the ProgramCompare class so that it can be used by two staff members to determine if the two supplied Java programs are the same or similar.
0 a+ e# C3 x; b% z4 {1 rThe staff must be able to:8 U0 U% A7 x/ F% ]  m* W5 ]
 Log on to the „system‟ using their user name, and a Personal Identification Number (PIN) which is a four digit number **.
! {/ A/ B% n4 `8 k9 v8 r+ ~1. The user should not be able to use the „system‟ until they have provided the correct user name and PIN combination. You should give them a second or third chance to get it right before shutting the „system‟ down.) \, I9 L/ y1 E7 L& V
 The interface should provide a menu so that the staff can:
6 |% b7 J  K7 n* d; L$ za) Enter the names of the two Java program files to be compared: s6 r+ Q1 p  G0 G7 a" P* q1 {* u0 M
 For this assignment, it will be assumed that the two Java program files are in the same folder as your program.
7 K; \) O* l8 r; S$ v; K3 r** You must use the two user names and PINs provided in your individual data available from the Assignment 2 page on Vista (see requirement 5 below). The user names and PINs should be included in your code, and the output to the screen should prompt the user with the user names and passwords (for marking purposes).
. E0 D8 P0 z4 GBSA104 Business Programming – 2007: Assignment 2% u/ c/ a( @/ o  w: M/ R8 J
Page 2 of 5
1 Y! T% N" i. m# @0 Kb) Print out to the screen all the lines of code that are the same; E/ ]  d' ?, t3 W& `  X* L
 Include the name of the file and the line number of the code being printed for each of the two files
9 s. T5 |$ d, sc) Print out to the screen all the available information regarding the evaluation of the two Java program files being compared# M# T6 M' K4 E! u- E; B, P5 P/ ]
 the name, username and department of the user
. f+ x3 _! w# h! W& ~& m2 ] the statistics of the comparison( s# f3 m6 b& X8 V; h5 C" \8 L2 q
- For example: the number of lines of code checked, the number of lines the same, the number of lines that are different
# P# N" i1 e3 ?2 R the recommendation for further checking8 J) Q  Z4 ]' s$ P2 G
- For example: if more than 5 (five) lines of code are the same in each Java program file, then print a recommendation to the screen that the staff member check the files more closely
0 y/ _# \# c) J2 {7 u" T the names of the two files compared
; t! N/ \7 a3 I8 T8 ~d) Leave the program (exit)$ u5 n9 g3 j5 [/ Y# p" X
The ProgramCompare class: (Total maximum 20 marks available): d. D' u1 \! {  B2 n
2. Provide a method/s to read in each line of code from the two files identified by the user: (assumed that the two Java program files are in the same folder as your program)# g1 S2 Q  S% `4 y. y4 g+ V
a) provide an error message if the files are not found or there is a problem opening them" g& e- G7 C" N" P2 x- `! D9 }
b) compare each line of code' r. P. Z9 H) s
c) print out the lines that are the same
# Y) h" k- S' H; X. od) count the number of lines compared / lines the same
7 Q4 o* w  Z, @. L/ n5 U6 g7 }6 [The AuthorisedUsers class: (Total maximum 20 marks available)# \7 S3 p, o6 M7 d
3. Provide an object that contains the name, username, PIN, and Department of the authorised users of the program (user names and PINs as provided in your individual data - see requirement 5 below)( [7 l- V$ v2 K6 i# m: `
4. Provide methods to:
! S* V1 ^: c5 [6 `. y; la) compare the stored username and PIN with the one entered by the user - return a value that indicates whether they match or do not match; H/ ^4 l+ T- ?7 k* K1 P
b) return the name of the authorised user
) K$ z" I2 v' Z" o1 d  S$ Y4 ic) return the name of the department of the authorised user
8 c1 s0 z. [$ gIndividual Data (Maximum 20 marks available)' E% O0 Q! T7 f% S: ]- j
5. You will be given two staff member names, usernames, PINs, and department name, plus a set of two Java program files to compare using your program. You will need to log onto the BSA104 Assignment 2 page on Vista to generate your individual data and instructions for this requirement. You will need to use your University of Tasmania (UTas) student number.0 V7 a- n2 u( q/ {) h8 F
Documentation (Maximum 10 marks available)* S4 Q/ P# G# ]; }/ U
6. Your program files should be fully documented, at least to the same standard as demonstrated in the textbook. This includes in-code comments, descriptions, and where appropriate, explanations for each new constructor, method and variable.
+ b5 T9 E, j6 M4 [1 P2 d1 e% OBSA104 Business Programming – 2007: Assignment 2* W2 p( V3 X: @/ H& _- [4 e
Page 3 of 5
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:53 | 显示全部楼层
上面是作业要求,然后前三个是给的java程序,要求自己修改- -
回复

使用道具 举报

发表于 2007-5-9 14:04:47 | 显示全部楼层
我的妈咪哦,这个已经超出了,我的一点点了
  s$ F8 G% Q1 w; e不过你要翻JAVA的类库说明。你有下载没有?
2 D) P+ y$ m4 J查询关于对比的函数。貌似关键字是contrast,还有compare
  {0 Q7 x6 O' h/ \3 b2 Y8 E. k# p" S! V& X2 p  a0 E5 |3 L8 Z2 x0 x" O
[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:05 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:06:19 | 显示全部楼层
,.....看来还要翻书哇....我学信息系统的- -
/ x5 |' @7 P/ L1 ^痛苦啊15搞要交..没觉睡了
回复

使用道具 举报

发表于 2007-5-9 14:07:54 | 显示全部楼层
不是翻书,是要翻在SUN下载的JAVA的手册,书有个毛用。
' k, O+ L* H: ?1 E- A可以下载到的 是 jdk-1_X_0-doc1 |0 h8 a6 p0 q. c

, W/ w: v7 \& s% T- s9 Y- A$ Q% [1 F[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:09 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|=|HERO|=战队 ( 皖ICP备19020640号 )|网站地图

GMT+8, 2026-2-14 16:44

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表