找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1558|回复: 20

谁会JAVA编程

[复制链接]
发表于 2007-5-9 13:27:08 | 显示全部楼层 |阅读模式
救急 ) N8 Z! F( V5 W3 F5 u. v* g7 Q6 \ D/ a, b6 A$ s5 X; 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 | 显示全部楼层
//*********************************************************************
1 K" M7 Z0 v. T  Q& k4 g9 [/ X+ m//  ProgramCompare.java         Provided by: DRS; m8 J( W# S% y2 q3 `' `. t; C& r" v
//1 t1 B$ B7 M5 y. V" R
//  Program shell for Assignment 2
+ T4 `5 `/ k7 J1 H, b//
$ r$ B0 _9 [% L0 @8 N//  Compares two text files line by line
3 y' m, w) P  [. |//*********************************************************************# e1 e4 ]0 ~4 H: n
' a6 S  G' {. G2 \% i5 h3 {
import java.io.*;7 E% m; E# K) {
! k1 U6 Z5 [/ |3 l3 R" a
public class ProgramCompare
  W- P5 Z. Q2 M! N6 Y{
, R/ ^8 T: `6 K9 B# E! u3 _# t5 t8 C        //-----------------------------------------------------------------& j$ e. S7 s; _% b
        // Constructor
( y5 x0 b/ F# l, X        //-----------------------------------------------------------------
/ i  k$ V1 t. Y+ v7 [' h5 Z# h        public ProgramCompare()1 [& j4 X7 {# `, @
        {  O& U- \& ~7 Y1 v6 i+ [
        }
- J# H( u- v1 K( Q% Z! L4 p! O4 |: Y5 x2 f' ~
        //-----------------------------------------------------------------
% |- _) R6 U1 A" n; k5 g        // Method for testing that class has been reached
6 x& w9 V% L8 B  q, A' X( `+ d3 _        //-----------------------------------------------------------------       
* [$ F! d# V- D! J6 }  m0 i) n+ P- l" q
        public boolean ProgramCompareReached()        
# i' @6 o: _, C: T, `7 t        {
* [- ?8 M: q; V5 w; J/ W' O      try 7 W9 z  _8 y1 @$ r
   {        
7 t  ~4 o( Y; k% r; w4 l& _                        $ S" J  c4 }6 z; j4 \# r+ ?- o+ a
                //********************************************************************6 ~* f7 ]$ T) ]8 ^% \2 T
                // Try-Catch Statement is used to handle exceptions - such as file not found
8 p; c% |8 F) s9 b                // Reading the files will need to be placed inside a Try-Catch - just like this one!
" x. ]% V9 Z9 V0 i+ d                // For more information see page 534 of the textbook
; T+ k4 m% g) `5 h9 ?                //********************************************************************; l! l. ~% r: ?. s% X7 l5 t4 M0 B" Q( ~
                    
8 t, u1 k8 I2 c- a' j. i+ b+ O- Z9 [        }
/ W& ]8 G; j4 R7 r/ S             catch (Exception ex) // Exception caught here and message displayed to the screen
7 [! S+ {) Z/ D* [          {# }: U# l* B3 h2 {9 `0 J
                    ex.printStackTrace (System.err);; u% k" j9 t$ {9 m( P
           System.out.println ("Error message goes here"); // Replace this error message with your own         
. C3 n: h! k4 h! ]) ?' E0 y        }
: r% c+ i* F# W                return true;
- c2 ^* J& u1 M. V        }/ p! k1 l" S5 U. r: g2 V( k" _

9 c- \' x$ D! d} // end of class ProgramCompare; n+ c# n* R' P; J

# l* w' U1 }' J/ D* J1 U//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:41 | 显示全部楼层
//********************************************************************% N6 M2 f2 z5 W/ D
//  ProgramCompareMenu.java    Provided by: DRS  u9 g" x/ F% G' N' `! A
//
3 W2 i9 H& y* P& u  ^//  Calls AuthorisedUsers.java and ProgramCompare.java
* C. |2 D/ R# f2 R3 E  q6 O/// ^! P) J2 d/ v/ q
//  Driver shell for Assignment 2.% ?5 {' E: h0 U5 ^
//********************************************************************- n2 t7 j2 b% ^

0 {- K, p4 S1 V( c! dclass ProgramCompareMenu
7 Y  o2 U& ?9 J; _- m/ L8 w{
. v& _) L6 m! f1 A    public static void main (String[] args)
  W! ^6 Y! _0 ]' ]6 C5 P& P+ m            {
- u" t# A1 K0 r$ c: q! j$ \+ I                //Check that the two classes ProgramCompare and AuthorisedUsers are reachable
# ?7 M) o  g9 c& t: q( J3 b                ProgramCompare reached1 = new ProgramCompare();
# u$ t. \2 D: w- S" w8 o; g                AuthorisedUsers reached2 = new AuthorisedUsers();        7 ]* r5 P% N( W* T6 ~* s& K
                System.out.println("ProgramCompare reached? " + reached1.ProgramCompareReached());4 }! l3 U- v# x; X6 s1 c
                System.out.println("AuthorisedUsers reached? " + reached2.AuthorisedUsersReached());        8 F. ?5 A4 U8 q7 @
        }$ I, {' B& X/ A' ?! W/ u
}// end of class ProgramCompareMenu
9 g9 k' k* l  g4 P& B* t! e; c; x$ i( a9 _0 C
//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:01:55 | 显示全部楼层
//********************************************************************& b; N* e7 }0 d6 y1 {+ e
//          AuthorisedUsers.java          Provided by: DRS' i2 I' ~# X8 x# I( ^  q
//               
! s( e& l; U/ j4 o//         Program shell for Assignment 2( J* R2 |3 J/ `7 v
//
1 w! L) N* R1 {//         Represents facts about an AuthorisedUser
- _5 {7 z2 m$ k; Z" Y//********************************************************************4 [( ]/ S2 X2 X8 f. ^9 ~) W
, l1 F$ H; m+ k' [7 f' L( V
public class AuthorisedUsers: P+ |" m, I, G$ w9 k6 w( f: |' L
    {% a* B: J. X8 B6 a" v% y/ |

, c, B3 \8 j, U  O2 A9 q        //-----------------------------------------------------------------+ p& B% i/ b8 I  {' g* C! _8 s4 P
        // Constructor
3 T" N! \0 P, n6 U% b- J4 @1 x        //-----------------------------------------------------------------; Q- c# W/ g% [% t9 ^% }
0 c4 L: v+ x: F8 J
        public AuthorisedUsers()( ~1 b$ S1 b2 b2 B2 ]2 V( c/ J
                {) F. x* u; R  m% t) v4 y
                }
0 ~' v2 F$ U% ^
: p- b5 X5 U2 M5 q& ?3 o        //-----------------------------------------------------------------
; O! B) S6 G6 e7 o+ g2 D& m        // Method for testing that class has been reached- ]8 \0 w, k: G5 w7 u' T
        //-----------------------------------------------------------------       
- ]; ^; Q7 E2 M. o' I+ U% V        public boolean AuthorisedUsersReached()+ d, h) p. C7 a4 j! K9 p2 Q- P
                {4 g2 h5 p8 m* F# W
                        return true;                        4 [, a9 ]: ^! }1 _, d% _2 C
                }- N& f# O# M# K+ J6 ]. D
               
: {& D# X. J- R    } // end of class AuthorisedUsers
  B7 e5 b1 F6 [# {7 u//-----------------------------------------------------------------
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:03:32 | 显示全部楼层
BSA104 Business Programming
* o2 c% D" W, CShanghai - 20070 j% h, ~9 q+ H) [/ a
Assignment 2
' j( M4 r- X$ L8 z  a* mDeadline 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)
& ~5 o8 g2 V! T0 t" n2 q1. 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.
4 k  j9 G% P1 u9 q. k+ eThe staff must be able to:0 _1 K; l( U9 a' V5 y
 Log on to the „system‟ using their user name, and a Personal Identification Number (PIN) which is a four digit number **.1 x0 A5 M: h- W: {! ^1 S. r$ J
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.6 V# ?; Y% J6 O
 The interface should provide a menu so that the staff can:% P" v5 x) e; C: e
a) Enter the names of the two Java program files to be compared
2 X# q9 `0 x/ ~: G- C2 r4 F, I0 r For this assignment, it will be assumed that the two Java program files are in the same folder as your program.. }5 d( Y: M/ q- _4 H5 d0 g
** 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).5 |, L( ?  N7 t; C' c2 {
BSA104 Business Programming – 2007: Assignment 2
6 M- P$ K% L5 W$ ^/ |, iPage 2 of 5
( J" m6 }! _$ D! I- s* Db) Print out to the screen all the lines of code that are the same
1 H6 ]% a0 A" z, n" y% p Include the name of the file and the line number of the code being printed for each of the two files4 p; j' L+ P0 i3 I. j* z
c) Print out to the screen all the available information regarding the evaluation of the two Java program files being compared: V8 J2 x$ O3 j* k/ Z2 E9 F
 the name, username and department of the user
+ K) c  @0 z$ x! D/ v' B6 \6 j the statistics of the comparison
& }, Z' ~- d. p% F/ y+ _" |6 f- For example: the number of lines of code checked, the number of lines the same, the number of lines that are different6 J) s2 S7 G0 E
 the recommendation for further checking# X* c' s; H+ c) _" R3 e5 U
- 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# x7 K7 L: ^( m, b- L& B: z
 the names of the two files compared
0 N$ |) e- _, n7 Q3 T1 Od) Leave the program (exit); o4 L$ h+ c' A% C) _
The ProgramCompare class: (Total maximum 20 marks available)
* j9 Y' V" }# g- H# i$ a& D$ ^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)/ n- K3 g' A- F
a) provide an error message if the files are not found or there is a problem opening them' U5 ?! A; _2 L4 d5 N* c
b) compare each line of code
3 @' t- U& G# Q) d) ic) print out the lines that are the same
  H8 w' ^+ B) U' Cd) count the number of lines compared / lines the same# d3 U9 Y7 K) I" C/ W
The AuthorisedUsers class: (Total maximum 20 marks available)
) f1 H$ b/ ~5 ~' A* U4 W3. 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)
& }2 h% a# P& u* v% s4. Provide methods to:
* F. x$ v& L3 _  e9 q+ b2 M  }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; n: u6 @: {8 m, A) h: q
b) return the name of the authorised user% m; F* y$ E1 {- P) @
c) return the name of the department of the authorised user" T% W: _  ^( D+ D* X/ e% h+ s+ Y
Individual Data (Maximum 20 marks available)
% S5 N3 x. a7 p# d. R5. 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.
! Z/ O+ \* m  C- s5 \, U0 pDocumentation (Maximum 10 marks available)
" \" f$ f7 Y3 n& p4 u  w) n6. 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.
7 i0 T3 w' }8 ^5 [: h' I- lBSA104 Business Programming – 2007: Assignment 2
" ^# P+ y6 v3 `; g0 @4 }Page 3 of 5
回复

使用道具 举报

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

使用道具 举报

发表于 2007-5-9 14:04:47 | 显示全部楼层
我的妈咪哦,这个已经超出了,我的一点点了2 p! d. T- z7 d3 P( i+ \0 u
不过你要翻JAVA的类库说明。你有下载没有?
! {5 ]% U, V& i& b. c1 y查询关于对比的函数。貌似关键字是contrast,还有compare
7 J0 K# R( i, ?) t. z2 @# g/ a/ ]
[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:05 编辑 ]
回复

使用道具 举报

 楼主| 发表于 2007-5-9 14:06:19 | 显示全部楼层
,.....看来还要翻书哇....我学信息系统的- -% {8 E; T) n& J2 g# _
痛苦啊15搞要交..没觉睡了
回复

使用道具 举报

发表于 2007-5-9 14:07:54 | 显示全部楼层
不是翻书,是要翻在SUN下载的JAVA的手册,书有个毛用。( g. C3 X; D2 n9 m3 E4 e/ P4 {
可以下载到的 是 jdk-1_X_0-doc
( U" a- v) ]1 L
# j  t) T& _8 l# r$ E7 w" N0 I[ 本帖最后由 =|HERO|=GreatWall 于 2007-5-9 14:09 编辑 ]
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-8-22 09:05

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

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