找回密码
 注册

QQ登录

只需一步,快速开始

查看: 819|回复: 20

谁会JAVA编程

[复制链接]
发表于 2007-5-9 13:27:08 | 显示全部楼层 |阅读模式
救急 ) O2 S4 B- l" A: O q- B' k* y. U- s2 E2 V. K% N# k' ~1 _7 Z7 D
回复

使用道具 举报

 楼主| 发表于 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 | 显示全部楼层
//*********************************************************************
/ I9 Z: z) U7 s) q//  ProgramCompare.java         Provided by: DRS# O6 c' d6 T# h9 ?, ]+ k  w
//3 f) y, Q: ~) d9 Z
//  Program shell for Assignment 2
! w: g  F" V: T; ]+ f& b' L//8 z* g* [$ K% r' M& K$ i
//  Compares two text files line by line
4 j( O& P$ v1 {4 j//*********************************************************************
9 v! w9 E3 z1 b7 S& U+ S; ^; |# Q% z! q: @: A/ x  q/ E5 \/ d/ P
import java.io.*;6 V1 n3 U/ C$ y) N& Q: `& L
5 D5 z0 K3 @3 R+ _
public class ProgramCompare
& r$ a- y" Z( _% m6 x( E{
+ g- ^' o" U+ _( S7 w2 W7 C# @        //-----------------------------------------------------------------
0 x1 ^) p$ ~1 R5 c. ?: A        // Constructor
- ^; R: ?' x* ]/ @. w        //-----------------------------------------------------------------4 G% T% j8 h( i! A: |
        public ProgramCompare()
4 y. g4 q4 c1 Q+ M9 V* ?5 d4 U        {% }  Z2 S+ V: D5 B+ ]
        }
3 v; r( C, U8 `; \5 m4 O9 U4 [/ H
        //-----------------------------------------------------------------) x& w9 X3 s; t: B9 _
        // Method for testing that class has been reached
& X% p! l2 v$ Q4 D/ f        //-----------------------------------------------------------------       
+ R- M9 j( L& r
- n2 T2 g9 |2 w% ]        public boolean ProgramCompareReached()         + R# {7 i3 W6 ~% S" H& {
        {9 U' g/ z+ Q7 f& f4 r1 t6 Y& d
      try
0 B, X! w' m1 ~5 [( _7 r, w  \   {        
0 H, ^/ h' ^9 o+ R4 M. S  n                        . {& _, u: H2 q2 ^
                //********************************************************************/ y9 ?8 @8 S# T
                // Try-Catch Statement is used to handle exceptions - such as file not found
# N4 D5 [' s+ A' `                // Reading the files will need to be placed inside a Try-Catch - just like this one!* r  J* D- j" G8 L+ t! J4 X, k$ X3 f4 q
                // For more information see page 534 of the textbook
7 D, T, |' z" C1 S                //********************************************************************' q* {& n1 g9 \9 B, m2 K
                    
, P% ^0 c  D5 v$ l: L        }& k& M# F! g  H# w/ f' m/ v* M
             catch (Exception ex) // Exception caught here and message displayed to the screen + n  f0 ?! H7 z- z
          {8 f1 j1 r/ x. N
                    ex.printStackTrace (System.err);
: U2 p! {' ?1 U% Y$ }           System.out.println ("Error message goes here"); // Replace this error message with your own          : X2 ]  A. w3 r7 r4 w3 x
        }
8 f( H  D8 c- U0 ~, m3 s8 }                return true;$ D5 a6 @: E" R& U" f" k
        }" U2 Y: s" [8 u
1 w8 E) d! t8 ]7 g  J
} // end of class ProgramCompare2 Z. i; @" x! c7 R6 s6 Z5 O1 p

* r% r7 a4 p' x$ z3 b//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:41 | 显示全部楼层
//********************************************************************& ~# S7 [; W4 g1 [2 g& U
//  ProgramCompareMenu.java    Provided by: DRS' S. J' T0 d  ]' h5 a) O# q' L  v
//. ~/ p5 `1 U' y) `. {' ^  K
//  Calls AuthorisedUsers.java and ProgramCompare.java
& _' J3 |# E- J& r//6 Y% {& @& `4 k0 b3 s, g& D2 r, u+ {
//  Driver shell for Assignment 2.+ ^# [4 z* w. s* x
//********************************************************************
! h! E1 \( |0 T' z  X1 Q8 P7 `1 l7 g
class ProgramCompareMenu5 M. A* a1 b) C
{" S+ }/ ?. N7 O+ z8 D
    public static void main (String[] args)( j8 o1 R  a% j' D. `
            {
- z8 B1 d6 V# O- Z: p) [                //Check that the two classes ProgramCompare and AuthorisedUsers are reachable1 ^4 t! C4 @7 G4 ?" \- P3 T
                ProgramCompare reached1 = new ProgramCompare();
! e) X! H: [, o3 a5 {6 G( e$ V                AuthorisedUsers reached2 = new AuthorisedUsers();       
# E- E4 l& e+ P$ x% l/ t  u                System.out.println("ProgramCompare reached? " + reached1.ProgramCompareReached());4 o9 E* P1 i# l4 F8 l; K, ?+ O
                System.out.println("AuthorisedUsers reached? " + reached2.AuthorisedUsersReached());       
" O. m- M8 ~! i0 ]        }) ~2 b( e1 _2 y0 j
}// end of class ProgramCompareMenu; Y# i& E; r* N' L5 }+ V7 D

; q2 S* Y7 ~# t//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:55 | 显示全部楼层
//********************************************************************+ t9 a1 y% D+ }1 ^( O
//          AuthorisedUsers.java          Provided by: DRS+ `# C7 M0 r$ [- a8 _& }. f
//                5 S9 r% T& }/ e5 k" q; r
//         Program shell for Assignment 2; `5 K8 v& G) U& p& X9 @1 h! `+ m
//! m9 C" F! U( H# \
//         Represents facts about an AuthorisedUser
. P! n4 p4 l9 @6 r//********************************************************************
( t6 O* t+ m2 \% m; I
, @0 I% v+ Y- U# D" m# \$ ppublic class AuthorisedUsers0 J* c0 x. z; i" v3 A
    {. S1 B$ P- E+ |) j2 M" ?0 v9 B5 p
7 j0 n  x( o  e$ _, I8 r
        //-----------------------------------------------------------------
$ n, L6 ~  y( g  i5 p        // Constructor
- \/ F% q! A1 }        //-----------------------------------------------------------------  q# r4 m4 Y/ U8 y' ]+ m

& f: D. X8 o: s+ Q0 o( R0 l' @        public AuthorisedUsers(); Q6 M/ e1 q2 y  y3 h  ~" R
                {0 ?8 G0 ^" K/ K  h
                }
1 J+ a+ _' [3 [6 x, Z% N5 K! _9 |# `6 t. [9 W8 v6 H( W' R1 [6 [( u
        //-----------------------------------------------------------------7 f5 C6 C2 r; @6 r8 l5 L
        // Method for testing that class has been reached
8 w; o8 C# I' H: D3 H* A        //-----------------------------------------------------------------        & |! P1 f4 V" ?# ~+ B& a
        public boolean AuthorisedUsersReached()- \: D) {4 `6 c0 u
                {
5 R- ]9 P( k) j  U9 k% L# v                        return true;                       
. t/ i6 ?; Z! T- n$ a                }
* F! b( l9 \5 E2 A& r: e" A" B; H. `               
: Z! s/ u3 T, P" Q% o2 a) F- Z    } // end of class AuthorisedUsers( Q; w" q  |! X( i  Y
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:32 | 显示全部楼层
BSA104 Business Programming: t8 ^9 `, [* i' `8 a
Shanghai - 2007* w" x7 k8 [2 c! \
Assignment 2
- \2 u, M- t; |0 x- W  k: {. k3 Z* n' S( LDeadline 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)  |7 i& ?  B5 g) @
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.- Q* W- e8 x1 R7 o$ l1 w# c+ {
The staff must be able to:
1 B( |5 ]. {; w. }) D7 j! p Log on to the „system‟ using their user name, and a Personal Identification Number (PIN) which is a four digit number **.) m* E7 I3 e, P, Y6 W' v( Z
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.) y" y1 z) S: y1 U8 q4 @
 The interface should provide a menu so that the staff can:3 R0 C5 R9 a  z% `
a) Enter the names of the two Java program files to be compared
# T1 @8 U, t: M1 t  X0 N For this assignment, it will be assumed that the two Java program files are in the same folder as your program./ c' |, R  d! R6 W& d4 E5 t
** 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).
2 G, P9 i; L- v6 v( CBSA104 Business Programming – 2007: Assignment 2
4 N) g  {+ r! y/ b# j: Y3 G7 ~Page 2 of 5
# h+ S4 M, h4 x0 pb) Print out to the screen all the lines of code that are the same
4 {1 f) [2 ~( n( P. o- r Include the name of the file and the line number of the code being printed for each of the two files
1 a' d2 d" B; \/ m/ k3 N0 r. `2 s: dc) Print out to the screen all the available information regarding the evaluation of the two Java program files being compared/ g, ?, i( L  G- n
 the name, username and department of the user8 R0 s# [% [# q4 R
 the statistics of the comparison) }' z& Q3 P0 }/ I( q$ b6 F. {
- For example: the number of lines of code checked, the number of lines the same, the number of lines that are different
% E5 T! Z& Z7 L the recommendation for further checking9 N  a/ s9 C: V7 H& W
- 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/ f; D) Q7 Q% l! H1 R- l. J5 t
 the names of the two files compared" \" |, e/ u3 _! l0 w
d) Leave the program (exit)
( _- r2 x+ g% J+ n" m. ?2 A' _The ProgramCompare class: (Total maximum 20 marks available)7 z3 d/ H% u; u9 t" b
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)
4 e2 ?( V0 ~& p9 m$ }% a, o* |a) provide an error message if the files are not found or there is a problem opening them
0 U: d" H3 _3 C$ h& f% Nb) compare each line of code# u4 O5 `6 k' `9 B6 H- w+ T
c) print out the lines that are the same) X4 p( S1 _: w# F5 ]
d) count the number of lines compared / lines the same6 `4 {. O9 W* q: I$ c# T( a
The AuthorisedUsers class: (Total maximum 20 marks available)
5 l. J, w: ~7 ~1 l9 h8 B; h( T3. 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)+ W; G7 J; K$ g0 N4 Y9 Z* `# P
4. Provide methods to:% m" C6 \% e  ^6 F
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
( ]) Z( r$ X) {0 S# V: t( mb) return the name of the authorised user
' a; w+ a. @7 \' Pc) return the name of the department of the authorised user. ]4 e( o* ^: W5 w: U- z0 O
Individual Data (Maximum 20 marks available)1 u$ {, d3 E- F
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.( E# f4 @: Z) ^
Documentation (Maximum 10 marks available)
- M( I. O, v3 T2 I+ t6. 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.
. V4 ?8 C. a* t: _/ l! m2 y3 ABSA104 Business Programming – 2007: Assignment 2
- x* T1 ?6 z4 i; QPage 3 of 5
回复

使用道具 举报

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

使用道具 举报

发表于 2007-5-9 14:04:47 | 显示全部楼层
我的妈咪哦,这个已经超出了,我的一点点了+ N6 v) g6 ^6 s  i2 U3 w+ [' j
不过你要翻JAVA的类库说明。你有下载没有?
" K+ |" B8 M8 D1 T, t8 W3 U查询关于对比的函数。貌似关键字是contrast,还有compare' |3 e$ f# `  n

1 q7 w5 i! Q8 H: U- R. Y[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:05 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:06:19 | 显示全部楼层
,.....看来还要翻书哇....我学信息系统的- -/ \% V1 \. c/ h6 |7 [8 _
痛苦啊15搞要交..没觉睡了
回复

使用道具 举报

发表于 2007-5-9 14:07:54 | 显示全部楼层
不是翻书,是要翻在SUN下载的JAVA的手册,书有个毛用。5 {. x. G" ]. k% `; Z
可以下载到的 是 jdk-1_X_0-doc; z/ G: ?, {6 `+ j7 L& z1 O" \
$ I' K5 q0 x+ D, S  Y" W( J' w9 ], v
[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:09 编辑 ]
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-1 12:02

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

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