找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1853|回复: 20

谁会JAVA编程

[复制链接]
发表于 2007-5-9 13:27:08 | 显示全部楼层 |阅读模式
救急/ I3 r$ x3 A' `5 ` 9 X* R, i. |. y6 J- Z0 c3 [$ D6 W; V' p
回复

使用道具 举报

 楼主| 发表于 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 | 显示全部楼层
//*********************************************************************
3 ~+ @: }! R! o4 [7 C7 c/ H4 \8 Z//  ProgramCompare.java         Provided by: DRS  n4 l' {, M; L8 ]
//2 U! T! \8 [0 n7 B1 b7 l6 b
//  Program shell for Assignment 2
& u6 \9 e* x, a4 c) `/ f//
- }* D8 w' E, X5 g' J# e//  Compares two text files line by line
: t4 x( Y6 }$ F7 A7 _& f) h0 F//*********************************************************************
; D# K! c9 X4 B1 |1 g$ `  b+ X. ^  Z' Q# ~: Q
import java.io.*;
1 c( i! K# c* e! J" n1 A% n% K% m2 O+ E$ F( j0 P$ D( {$ v
public class ProgramCompare
) g' f) H4 M$ j0 q: W9 ~{2 J8 C7 s: X& ^4 u! G8 l* p: R
        //-----------------------------------------------------------------* @1 o9 g. i1 Q
        // Constructor) m3 A& U4 I7 _. p; V+ e7 s
        //-----------------------------------------------------------------& s0 `! x5 b( h* h1 |
        public ProgramCompare()1 C/ p1 ]. o% h3 `! M) f
        {
& s4 Z+ u2 L" T0 g5 w  Y+ _        }
1 W+ r" H5 T: O$ L$ C" ~8 u" Y4 E  @' x% [5 Y3 ]' N$ h3 v
        //-----------------------------------------------------------------, ]$ K$ U8 Q3 {) S0 ^! Q) p
        // Method for testing that class has been reached
) ~/ m( }3 W& h0 D; a* {3 X        //-----------------------------------------------------------------        + f6 z0 ]/ l/ B% R

. o# m4 U0 W+ K        public boolean ProgramCompareReached()        
2 H1 K# j1 d. }  \9 H3 {        {0 z* }' ?; R! G
      try * k9 D0 n7 b& ~( Z$ X5 j
   {        
4 B4 m& q0 `; H                        3 o- \1 |9 d+ s  S1 F; K- N
                //********************************************************************0 S8 `7 V' }# W' E
                // Try-Catch Statement is used to handle exceptions - such as file not found
! u0 j7 o7 o7 S1 D% w                // Reading the files will need to be placed inside a Try-Catch - just like this one!" n; n! z6 i6 k# s
                // For more information see page 534 of the textbook$ _* r$ H( z& L: N0 W$ H' n  x8 j
                //********************************************************************
1 S. U* k9 `: k8 m, p4 V( ?                     ) h% x9 X$ F) i0 \3 d- ~. c% _
        }( O; U) i5 p; i2 {$ y; t
             catch (Exception ex) // Exception caught here and message displayed to the screen   o0 \4 M* }, s9 k! v# [, H0 Y+ u
          {" _, T$ t- u6 T! o( H/ e
                    ex.printStackTrace (System.err);: Y  e7 V, P1 i3 v9 G5 @7 y& u" G
           System.out.println ("Error message goes here"); // Replace this error message with your own          * q9 e* u  o2 A! G
        }
! s* w' S, Z. I  H' f                return true;
4 c4 J; y1 I2 ^- a2 ]        }) Y7 ^2 |! H$ J$ o; H3 S# ?4 @2 q4 U

2 n( E4 j0 S' L- D- \( c} // end of class ProgramCompare
2 [( K6 N/ W# y& Q# W2 x" _6 K
# m" I' F7 ~) A! u: b//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:41 | 显示全部楼层
//********************************************************************( l& n+ Y. _+ j# N7 ?
//  ProgramCompareMenu.java    Provided by: DRS
- o2 X# M1 u+ y4 q. N1 l  c//  v# y  k- t) G6 Q7 f) D; w
//  Calls AuthorisedUsers.java and ProgramCompare.java' L, D$ z+ m7 M
//# {6 z4 z- w( W2 {3 Q# m* [+ m
//  Driver shell for Assignment 2.1 _/ Q5 g( U$ M5 u
//********************************************************************
6 p' T! }" G+ Z3 \! e; w9 T
- p' q1 f5 q+ h) O% d: V, qclass ProgramCompareMenu$ b4 U6 O+ N1 D5 X) v2 c
{
' \- u% [2 K/ l: C    public static void main (String[] args)3 h( D( z6 Y) ~8 Q& r
            {9 {3 L# s) P/ e- N6 p; P5 J0 x
                //Check that the two classes ProgramCompare and AuthorisedUsers are reachable
3 |9 J/ I5 j1 @9 Y0 ?% F1 r" g                ProgramCompare reached1 = new ProgramCompare(); ! w+ Q+ t" z. L4 z; Y4 E  D; w
                AuthorisedUsers reached2 = new AuthorisedUsers();       
: c$ {0 j* o; ]& _' n7 v                System.out.println("ProgramCompare reached? " + reached1.ProgramCompareReached());2 M5 G# i3 j2 u" l# [$ L
                System.out.println("AuthorisedUsers reached? " + reached2.AuthorisedUsersReached());        & ^2 l8 Y" S2 t8 Z3 t* I
        }
- A) g8 o0 d+ n$ p9 _& Y8 Q}// end of class ProgramCompareMenu
4 E# T1 q& Y! u0 [* E$ b% q( I/ K& s3 G3 [/ s9 `5 y& y0 p# ^
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:55 | 显示全部楼层
//********************************************************************
' n' N, ~, z# ^//          AuthorisedUsers.java          Provided by: DRS
5 w3 H9 I( e3 ~! ]//                - h$ C5 h0 N3 x0 [+ I
//         Program shell for Assignment 2' b5 B5 a# B' _% x6 t* M9 w
//) N8 Q+ M- M( U
//         Represents facts about an AuthorisedUser
4 w0 f/ ~9 x  s; ^4 d. {//********************************************************************
0 A) ?7 Z7 _* @. B3 o  C$ N* J  g- z- `7 M7 L3 @1 G
public class AuthorisedUsers. F) E# E1 [$ I6 T
    {
7 e$ j% z7 j% N1 {) R' Z5 n' I5 x* E0 A
        //-----------------------------------------------------------------
5 D5 ^1 R% m# }. G- G! e# u        // Constructor: X& ~2 v) \+ S. m0 }
        //-----------------------------------------------------------------
- V; y0 p" ?4 e. g: O) K% J9 f
$ g' y& s9 C# O3 j* P        public AuthorisedUsers()2 c: B; ^# j/ h9 B% z4 g
                {
: H8 e) q( Z+ r) D                }3 P% l' q1 |0 @3 m0 g% Q" |* _  q9 @' k

" O4 Q: N/ C, z9 r. P        //-----------------------------------------------------------------, m4 Q- H1 Y+ s$ H
        // Method for testing that class has been reached: o$ Y% E- y1 X8 h6 ~" z2 p
        //-----------------------------------------------------------------        8 O! q. L0 @, R  s" [/ g$ _+ S
        public boolean AuthorisedUsersReached()
# J4 b  z) L; O/ u; G4 _- L0 D                {& V9 M" Q$ Y* k, R% v( d; z1 f
                        return true;                        : s# N: ]7 n: \/ ~# ?: R- X
                }  y8 U5 P2 h1 h
               
) A; q* I* [' i7 |( s0 V3 e    } // end of class AuthorisedUsers0 |! \7 d4 i* {
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:32 | 显示全部楼层
BSA104 Business Programming% b( }8 o6 _- P! f* W- ^
Shanghai - 2007
0 Z1 P, ^2 f4 D6 IAssignment 2
. O5 {. C3 C$ A" A( eDeadline 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)2 r' `+ h5 {8 P- A. Q' m" H
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.
( X  g. H2 i% [; bThe staff must be able to:
  M$ g8 `; K/ j- Z Log on to the „system‟ using their user name, and a Personal Identification Number (PIN) which is a four digit number **.9 U2 x, k/ G% I$ g! P0 S
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.  W$ q9 w8 U) a9 C/ F
 The interface should provide a menu so that the staff can:+ d: I6 r2 ^& D! o3 j
a) Enter the names of the two Java program files to be compared
# H! }" `# |, z0 J: i6 H) a For this assignment, it will be assumed that the two Java program files are in the same folder as your program.
6 P# v. o% j" l* K** 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).
& C) q  e# }7 [( ]: [4 D, ^BSA104 Business Programming – 2007: Assignment 2, s( i3 w- ^1 O, U) C2 a7 Z1 V
Page 2 of 5
# X$ a$ P' }; _0 |b) Print out to the screen all the lines of code that are the same# t! F- U1 }( v" o1 s* _
 Include the name of the file and the line number of the code being printed for each of the two files
0 Q: N3 N4 q+ f" J2 ?0 t# v( b5 ~3 ~c) Print out to the screen all the available information regarding the evaluation of the two Java program files being compared
0 }  M  n* K' e+ j: b  } the name, username and department of the user0 n4 ^5 K! ~$ j" ?" P0 O: i* X
 the statistics of the comparison
" C2 s9 S' Q/ q* l1 p7 [( A- For example: the number of lines of code checked, the number of lines the same, the number of lines that are different/ x3 d7 Z2 J  m$ R6 f! f
 the recommendation for further checking) w- o! a% o" U; p
- 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 closely1 o  Y9 R; c3 V+ s2 R: E
 the names of the two files compared8 l7 ^) b/ t& m6 {0 r3 f3 A
d) Leave the program (exit)! R# x! z5 Z' U; j3 s
The ProgramCompare class: (Total maximum 20 marks available)3 e. e' T4 o8 H" C0 U4 ?! J
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)/ |* w; d6 t7 K
a) provide an error message if the files are not found or there is a problem opening them9 o! i& `$ t9 G' D, q( c/ o
b) compare each line of code
9 |) i' x$ s; K8 K% A1 ~c) print out the lines that are the same
9 r  K  u6 d( L/ l0 M" C8 ~& j7 |: |d) count the number of lines compared / lines the same2 b  _' \  }3 R) u1 p+ n
The AuthorisedUsers class: (Total maximum 20 marks available)
: F' _( ^  q5 ~$ c/ I3 {; h3. 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)3 w* ?# k8 Z& p0 C0 F, _. c
4. Provide methods to:2 o) L4 Z3 q9 E8 Q6 p; `
a) 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
" o, ^6 d" a3 G! Lb) return the name of the authorised user* ?8 a/ P' S- J9 o
c) return the name of the department of the authorised user' A( ]* A% }( U
Individual Data (Maximum 20 marks available)
$ t+ H- }, W6 i' T' z2 Y% B5. 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.
- Z2 b$ P+ d5 c9 o4 [: [8 JDocumentation (Maximum 10 marks available)% N. h1 n/ z8 u: j% }; j
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.
! v! R! R2 f2 m, [& K, OBSA104 Business Programming – 2007: Assignment 2
6 l6 v: i* v. n+ A8 s1 i4 R8 H0 XPage 3 of 5
回复

使用道具 举报

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

使用道具 举报

发表于 2007-5-9 14:04:47 | 显示全部楼层
我的妈咪哦,这个已经超出了,我的一点点了1 l8 i# {8 I% M+ L4 `
不过你要翻JAVA的类库说明。你有下载没有?' U4 D3 `- R5 G: Y! s) q( G9 Z8 y# ~
查询关于对比的函数。貌似关键字是contrast,还有compare$ K$ L% ], b) P- i8 P
" u; ]+ U5 R+ ^' |
[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:05 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:06:19 | 显示全部楼层
,.....看来还要翻书哇....我学信息系统的- -6 q8 p$ w, B5 `" c/ w& h
痛苦啊15搞要交..没觉睡了
回复

使用道具 举报

发表于 2007-5-9 14:07:54 | 显示全部楼层
不是翻书,是要翻在SUN下载的JAVA的手册,书有个毛用。4 G8 H( A2 }/ C9 s& F: K$ V5 [- B+ W
可以下载到的 是 jdk-1_X_0-doc( a3 t  ^: Q2 a

" R- q# u( r4 o- W7 P5 N, B2 X[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:09 编辑 ]
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-11-23 22:47

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

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