Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1877|回复: 6
打印 上一主题 下一主题

JAVA高手帮帮忙

[复制链接]

16

主题

1

好友

152

积分

高级会员

Rank: 3Rank: 3Rank: 3

跳转到指定楼层
1#
发表于 2009-7-3 10:53 PM |只看该作者 |倒序浏览
各位高手帮帮忙,这是小弟的作业题目(英文)请别介意。

Task 1
(a) Define the class Item to store the details of an item sold
in the bookshop. Each object of Item should store the
following information:
· Item number
· Item description
· Selling price
· Quantity on hand
Besides the set and get methods, Item class should
also include:
· A no-argument constructor
· A constructor with parameters
· The method equals that returns true if two objects
contain the same information.
(b) Write a test driver to test the various operations of the
class Item.
Task 2
Create an application program that declares an array of 100
elements of type Item. Your program should provide the
following operations which the user may invoke from a menu:
· Add a new item into the array (duplicate entries are not
allowed).
· Amend the details of an item.
· Search for an item by item number.
· Enter a sales transaction (the quantity on hand has to
be reduced accordingly).
· Input stock received (the quantity on hand has to be
updated accordingly).
· List details of all items – one item’s detail per line, with
line numbering.

红字是我要问的,请帮忙,谢谢。

[ 本帖最后由 derrick90 于 2009-7-4 11:09 AM 编辑 ]




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2009-7-3 11:05 PM |只看该作者
原帖由 derrick90 于 2009-7-3 10:53 PM 发表
各位楼主帮帮忙,这是小弟的作业题目(英文)请别介意。

Task 1
(a) Define the class Item to store the details of an item sold
in the bookshop. Each object of Item should store the
following in ...



· A no-argument constructor
· A constructor with parameters

constructor 就是主建構函數

class A {
    public function A() {}  //這個 A 就是constructor
}





如何初始化 Array 應該去看你的教學課本, 這是基本上所有課本或教學網站都會教的




Search 就使用循環搜索 Array 中每個 Class 中的 item number 屬性值




更改 Class 屬性更加不用說了



回复

使用道具 举报

16

主题

1

好友

152

积分

高级会员

Rank: 3Rank: 3Rank: 3

3#
发表于 2009-7-7 06:37 PM |只看该作者
请帮帮忙,要交了还是有问题,谢谢。
不懂怎样加  Quantity

public class Item {
    private int itemNumber;
    private String itemDescription;
    private double sellingPrice;
    private static int quantityOnHand;
        
        public Item() {
    }
   
    public Item(int in,String id,double sp){
            itemNumber=in;
            itemDescription=id;
            sellingPrice=sp;
    }
        
        public int getItemNumber(){
                return itemNumber;
        }
        public void setItemNumber(int sin){
                itemNumber=sin;
        }
        public String getItemDescription(){
                return itemDescription;
        }
        public void setItemDescription(String sid){
                itemDescription=sid;
        }
        public double getSellingprice(){
                return sellingPrice;
        }
        public void setSellingprice(double ssp){
                sellingPrice=ssp;
        }
        public static int getQuantityOnHand(){
                return quantityOnHand;
        }
        public static void setQuantityOnHand(int sqoh){
                quantityOnHand = sqoh;
        }   
}





import java.util.Scanner;

public class testItem {

    public static void main(String [] args) {
            Scanner input = new Scanner(System.in);
            System.out.print("Enter the number of book:");
            int num = input.nextInt();
            Item[] ItemArray = new Item[num];
            for (int i = 0 ; i < ItemArray.length ; i++){
                    ItemArray = inputItemInfo();
            }

            System.out.println("code   description     price     quantity");
        System.out.println("=========================================");
            for (int i = 0; i < ItemArray.length;i++){
                    System.out.printf("%d   %s     %.2f     \n", ItemArray.getItemNumber(),ItemArray.getItemDescription(),ItemArray.getSellingprice());
            }
    }
    public static Item inputItemInfo(){
   
    Scanner input = new Scanner(System.in);
    System.out.print("Enter the code :");
    int itemNumber = input.nextInt();
    System.out.print("Enter the description :");
    String itemDescription = input.next();
    System.out.print("Enter the selling price :");
    float sellingPrice = input.nextFloat();
   
    Item item = new Item(itemNumber,itemDescription,sellingPrice);
    return item;
    }   
}


[ 本帖最后由 derrick90 于 2009-7-7 07:14 PM 编辑 ]


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

4#
发表于 2009-7-7 09:10 PM |只看该作者
下在property 里

private int PQuantity;

public int getSize() { return PQuantity; }
public void setSize(int value) { PQuantity= PQuantity+  value; }


回复

使用道具 举报

16

主题

1

好友

152

积分

高级会员

Rank: 3Rank: 3Rank: 3

5#
发表于 2009-7-7 09:38 PM |只看该作者
解决了,for ..loop 还是不行,谢谢帮忙


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

6#
发表于 2009-7-8 01:58 AM |只看该作者
原帖由 derrick90 于 2009-7-7 09:38 PM 发表
解决了,for ..loop 还是不行,谢谢帮忙



不明白你所說的 for loop 有甚麼不行的


回复

使用道具 举报

16

主题

1

好友

152

积分

高级会员

Rank: 3Rank: 3Rank: 3

7#
发表于 2009-7-15 07:07 PM |只看该作者
帮帮忙,谢谢。。
帮我解决infinite loop的问题


import java.util.*;

public class HandleExceptionDemo {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    boolean continueInput = true;

    do {
      try {
        System.out.print("\nEnter an integer: ");
        int number = scanner.nextInt();

        // Display the result
        System.out.println("\nThe number entered is " + number);

        continueInput = false;
      }
      catch (InputMismatchException ex) {
        System.out.println("Try again. (Incorrect input: an integer is required)");
        
      }
    } while (continueInput);
  }
}


回复

使用道具 举报

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

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 06:29 PM , Processed in 0.110682 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部