|
查看: 1322|回复: 12
|
可以拜托帮我看看我的java code吗^_^
[复制链接]
|
|
|
java assignment的 due date快到了><"
希望佳礼的各位programming前辈们可以帮我看看我的code
请给我一些提示 多多指教
- import java.util.Scanner; //import java.util.Scanner class to read user input
- import java.util.InputMismatchException;
- public class Main //public class that contain public static void main
- {
- private static Scanner scan = new Scanner(System.in);
- private static Assest[] ass = new Assest[100]; // array of objects
- private static int choice = 0;//choice is used to control switch statement
- private static int choice2 = 0;// choice 2 is used to control switch statement
- private static int a, b; //a and b are used to control for loop
- private static int counter = 0; //how many assests user want to enter, and which assest user want to add, amend, write-off, searching
- private static String question; //question ask user is he/she really want to written-off that assest
- private static boolean loop = true; //determine anymore input is needed
-
- private static String mainID, mainDS, mainDT;
- private static int mainOD = 0;
- private static double mainCP = 0.0;
- public static void main(String[] args)
- {
- for(a = 0; a < 100 ; a++)
- {
- ass[a] = new Assest(); // initialize all assests as empty assests by using default constructor
- }
- do
- {
- try
- {
- System.out.println("How many assest do you want to enter (only 1-100)? : "); //prompt user how many assest user want to enter
- counter = scan.nextInt();
- loop=false;
- }
- catch(InputMismatchException e)
- {
- System.out.println("Error Occured: only accept number without decimal");
- scan.nextLine();
- loop = true;
- }
- }while(loop || counter < 1 || counter > 100);
- for(a = 0; a < counter; a++) //prompt user to key-in all the details of assest
- {
- scan.nextLine();
- System.out.println((a+1) + " assest - assest ID :");
- mainID = scan.nextLine();
- System.out.println((a+1) + " assest - description :");
- mainDS = scan.nextLine();
- System.out.println((a+1) + " assest - date purchased :");
- mainDT = scan.nextLine();
- do
- {
- try
- {
- System.out.println((a+1) + " assest - order number :");
- mainOD = scan.nextInt();
- System.out.println((a+1) + " assest - cost price :");
- mainCP = scan.nextDouble();
- loop=false;
- }
- catch(InputMismatchException e)
- {
- System.out.println("Error Occured: only numbers are accepted");
- scan.nextLine();
- loop=true;
- }
- }while(loop);
- System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
- ass[a] = new Assest(mainID , mainDS , mainDT , mainOD ,mainCP);
- }
- //do-while to control the remaining program, it will continue running unless user change the value of choice to -1
- do
- {
- do
- {
- try
- {
- System.out.println("\n----------------------------");
- System.out.println("1. add new assest (1-100)");
- System.out.println("2. amend an assest (1-100)");
- System.out.println("3. search assest (1-100)");
- System.out.println("4. write-off an asset (1-100)");
- System.out.println("5. list all assest (1-100)");
- System.out.println("6. equality checking (1-100)");
- System.out.println(">>>There is " + Assest.getNo() + " Assest stored<<<");
- System.out.println("---------(-1 to quit)--------");
- choice = scan.nextInt();
- loop=false;
- if(choice == -1)
- break;
- }
- catch(InputMismatchException e)
- {
- System.out.println("Error Occured: only numbers are accepted");
- scan.nextLine();
- loop=true;
- }
- }while(loop);
- switch (choice)
- {
- case 1: Add();
- break;
- case 2: Amend();
- break;
- case 3: Search();
- break;
- case 4: WriteOff();
- break;
- case 5: ListAll();
- break;
- case 6: Equality();
- break;
- }
- }while(choice != -1); // while user didn't enter -1, this program will continue running
- System.out.println("------------------\nThe End , Good bye\n------------------\n");
- }
- public static void Add()
- {
- do
- {
- try
- {
- System.out.println("How many assest do you want to enter (only 1-100 or -1 to leave)? : "); //allow to add new assest
- counter = scan.nextInt();
- loop=false;
- if(counter == -1)
- break;
- if(counter > 0 && counter < 101){
- if(ass[counter-1].getST().equals("Written-Off")) //don't allow user to add existing assest
- {
- scan.nextLine();
- System.out.println((counter) + " assest - assest ID :");
- mainID = scan.nextLine();
- System.out.println((counter) + " assest - description :");
- mainDS = scan.nextLine();
- System.out.println((counter) + " assest - date purchased :");
- mainDT = scan.nextLine();
- do
- {
- try
- {
- System.out.println((counter) + " assest - order number :");
- mainOD = scan.nextInt();
- System.out.println((counter) + " assest - cost price :");
- mainCP = scan.nextDouble();
- loop=false;
- }
- catch(InputMismatchException e)
- {
- System.out.println("Error Occured: only numbers are accepted");
- scan.nextLine();
- loop=true;
- }
- }while(loop);
- System.out.println("@@@@@@@@@@@@@@@@@@@@@>>ADDED<<@@@@@@@@@@@@@@@@@@@@@");
- ass[counter-1] = new Assest(mainID , mainDS , mainDT , mainOD , mainCP);
- }
- else
- System.out.println("\n!!!!!Not allow to add existing assest!!!!!");
- }
- }
- catch(InputMismatchException e)
- {
- System.out.println("Error Occured: only accept number without decimal");
- scan.nextLine();
- loop = true;
- }
- }while(loop || counter < 1 || counter > 100);
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 26-6-2010 07:57 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 26-6-2010 07:59 PM
|
显示全部楼层
另外一个含有constructor的class
拜托各位前辈们帮我看看谢谢^_^ |
|
|
|
|
|
|
|
|
|
|
发表于 27-6-2010 05:49 PM
|
显示全部楼层
你 的 ERROR CONSOLE 那边 出 什么 ERROR 哦 ? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 27-6-2010 06:40 PM
|
显示全部楼层
本帖最后由 qiqimon5566 于 27-6-2010 06:43 PM 编辑
没有error.. 只是想知道这样的code 符合标准吗=="
因为code 只有1人在写 我已经很累了
很懒惰去加更多的command block 或者 line 或者加强了
所以我的code 连一个JFrame dialog box GUI都没有
我知道 这其实还蛮差 和 不负责任
可是我还是很希望听取各位前辈们的金玉良言
如果可以 我想交了>_<"  |
|
|
|
|
|
|
|
|
|
|
发表于 28-6-2010 03:44 PM
|
显示全部楼层
其实 你 可以 把 那些 GET - SET 写在 另外 一个 CLASS FILE 里面 ( 通常我们叫 BEAN FILE ) ..
可以的话 , 就 尽量 用 ABSTRACT 或者 INTERFACE , 因为 JAVA 的 OOP concept 不鼓励 一次过 写完 全部 CODE 在 同一个 FILE 里面  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 5-7-2010 07:41 PM
|
显示全部楼层
其实 你 可以 把 那些 GET - SET 写在 另外 一个 CLASS FILE 里面 ( 通常我们叫 BEAN FILE ) ..
可以的话 ...
兔仙人 发表于 28-6-2010 03:44 PM 
谢谢你的建议
学校刚开始要教inheritance 和 abstract 所以将加在assignment2 ^^
目前的是assignment1 虽然学校教的唯一一个gui只有joptionpane
可是看到有一个人 做了全gui jtextfield jframe jmenubar 等等
再看自己的 感觉到 自己好失败/.\ |
|
|
|
|
|
|
|
|
|
|
发表于 5-7-2010 10:25 PM
|
显示全部楼层
所以你要學習看 API  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-7-2010 08:28 PM
|
显示全部楼层
所以你要學習看 API
兔仙人 发表于 5-7-2010 10:25 PM 
请问什么是API?
还没学到== wiki解释看不太懂== |
|
|
|
|
|
|
|
|
|
|
发表于 6-7-2010 09:40 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 7-7-2010 05:24 AM
|
显示全部楼层
API , 學校 是不會 教的 。
不過 我給個例子你 , 你 自己 看看
這個就是 STRING 的 API , 裡 ...
兔仙人 发表于 6-7-2010 09:40 PM 
谢谢你哦
我会加油的^^
那我想请问你
还有哪些是重要
又是学校不会教的吗? |
|
|
|
|
|
|
|
|
|
|
发表于 7-7-2010 09:10 AM
|
显示全部楼层
本帖最后由 兔仙人 于 7-7-2010 09:12 AM 编辑
學校只是 教 基本 的 知識 而已 。。
例如 JAVA , 只是教基本的 用法 。 如果 想 繼續 ADVANCE , 就 得 選擇 你 要 走 的 方向 。
PS : J2SE , J2ME , J2EE 。 本仙人 認為 EE 比較有錢途  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 7-7-2010 09:45 AM
|
显示全部楼层
我刚刚把 j2se j2me j2ee j2fx 都下完了=_="
呵呵 想问j2ee 和 j2se有不同吗?
我是买了本 算是教得还蛮全面的java书
可是好像没教我分类 和选择@_@
谢谢你的建议哦^_^ 我也想学enterprise edition ^_^ |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|