华人德语培训中心     Fahrschule Rainer     
第1页,共2页 1 2 最后最后
显示结果从 1 到 10 共计 15 条

混合查看

上一文章 上一文章   下一文章 下一文章
  1. #1
    高级会员 新生儿
    注册日期
    2007-06-04
    文章
    250
    Thanks
    0
    Thanked 4 Times in 4 Posts
    声望力
    19

    预设 请教java编程问题!紧急!!!

    最近选修了最基础的java编程,刚开始尝试中。。。这周要交的一个作业不太会,麻烦高手们帮帮我!!!

    Erstellen Sie ein Telefonverzeichnis (2 Punkte)
    a) mit einem Array für die Speicherung von folgenden Namen und Telefonnummern.

    String daten="Name: Bastian Schweinsteiger Telefonnr: 21321231";
    String daten1="Name: Michael Ballack Telefonnr: 4324234";
    String daten2="Name: Lukas Podolski Telefonnr: 4324351";

    b) Schreiben Sie eigene Methoden für das Hinzufügen, Löschen und Ausgeben der Daten.

    c) Loeschen Sie Michael Ballack aus dem Array

    下面是我自己写的,但怎么运行都不对,希望会的同学尽快帮我改正,或者写个新的!!!拜托拜托了!!非常紧急!
    class Person {
    String name;
    int phone;
    }
    class PhoneBook{
    static Person[] book;
    static int nEntries=0;

    static void enter (String name, int phone){
    if (nEntries>=book.length)
    Out.println("-- phone book full, entry " + name + "ignored");
    else{
    book[nEntries] = new Person();
    book[nEntries].name = name;
    book[nEntries].phone = phone;
    nEntries++;
    }
    }
    static int delete(String name){
    int i=0;
    while (i<nEntries && !name.equals(book[i].name))
    i++;
    if(i == nEntries)
    return -1;
    else {book[i].name=null;book[i].phone=0;
    return 0;}
    }

    static void printBook(){
    for(int i =0; i <book.length;i++)
    Out.println("Name: "+book[i].name+" Phone number: "+book[i].phone);
    }

    public static void main (String[] arg) {
    book = new Person[10];
    In.open("Telefonverzeichnis.txt");
    String name=In.readString();
    int phone;
    while (In.done()){
    phone =In.readInt();
    enter(name,phone);
    name =In.readString();
    }
    In.close();
    printBook();
    Out.println();

    name=In.readString();
    phone=In.readInt();
    enter(name,phone);
    Out.println();
    Out.println();

    for(;;){
    name = "Michael Ballack";
    phone=delete(name);
    if (phone== -1)
    Out.println(name + "unknown!");
    else
    Out.println("Phone number of "+ name +" ist deleted!");
    Out.println();
    Out.println();
    printBook();
    Out.println();
    Out.println();}
    }
    }

  2. #2
    TriVector
    游客

    预设 回复: 请教java编程问题!紧急!!!

    错误信息是什么?

  3. #3
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    引用 作者: TriVector 查看文章
    错误信息是什么?
    CCNA kao de zen me yang le? wo zhi dao ni shi shui le.......zai code li bian ru zi ji de mingzi,ju shuo ni asp bu cuo, ni tong wu lai, jiu shi nage ai kan nü ren wo zui da de nage qing dao xiao di

  4. #4
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    for(;;){
    这里用了死讯欢乐。 我就不信不出错
    Out.println();我这边出错!不知道你用的啥。。。code有些可以借鉴,而且写得挺简单的。。但是主程序里你要打开文件.txt什么的。。我这边用你的代码太多错误,花那个时间看你的错误还不如自己编个新的而且由于整个思维方式不是俺的,俺又失去java灵感了。。都是颇sql弄得

    这个是整个代码既有添加和删除的methoden, 那个array俺设成的是类的数组。。
    而且也删除了那个micheln 就是代码里可能有冗余码。。
    2分能给你1,5或者1分。。靠至少都运行了啊。。。用这个代码的话你们老师不给你分。。我在家诅咒他

  5. #5
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    /*
    * Created on 2007-4-9
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    package Test2;

    /**
    * @copyright
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class TesterLab02 {
    public static void main(String[] args) {



    Person [] p=new Person[3];LinkedList listTest2=new LinkedList();
    p[0]=new Person("we","w","23w0w");

    p[1]=new Person("2c "," 2d ", " 11-3-1999w1 ");

    p[2]=new Person("Michael","Ballack","4324234");

    listTest2.add(p[0]);listTest2.add(p[1]); listTest2.add(p[2]);
    System.out.println(" ---------ADD Telephonnummer-------");
    System.out.println(listTest2);
    System.out.println(" ---------Loeschen Telephonnummer-------");
    boolean l;
    l=listTest2.remove(p[2]);
    if(l) {System.out.println(p[2]+" geloescht \n ");
    System.out.println("new Telephon Buch is ");}
    else System.out.println(" nicht geloescht");
    System.out.println(listTest2);


    }




    }
    此篇文章于 09-05-15 23:59 被 星星点 编辑。

  6. #6
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    package Test2;
    /*
    * Created on 2007-4-8
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    /**
    * @copyright
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class Person {

    String firstName;
    String lastName;
    String telephon="";
    Person(){
    this("unknown", "unknown", "unknown");
    }
    Person(String firstName){
    this(firstName, "unknown", "unknown");
    }
    Person(String firstName, String lastName){
    this(firstName, lastName,"unknown");
    }
    Person(String firstName, String lastName, String telephon){
    setFirstName(firstName);

    setLastName(lastName);
    setTelephon(telephon);
    }
    void setFirstName(String newfirstName){
    this.firstName=newfirstName;
    }
    void setLastName(String newlastName){
    this.lastName=newlastName;
    }
    void setTelephon(String newtelephon){
    this.telephon=newtelephon;
    }
    String getFirstName(){
    return firstName;
    }
    String getLastName(){
    return lastName;
    }
    public String toString(){
    return "\n" +
    "firstName: " + firstName + " |\t\n" +
    "lastName: " + lastName + " |\t\n" +
    "Telephonnumer: " + telephon + " |\n";
    }

    }

  7. #7
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    package Test2;
    /*
    * Created on 2007-4-8
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    /**
    * @copyright
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class ListItem {
    Person item;
    ListItem next;
    ListItem prev;
    public ListItem(Person item){
    if(item!=null) this.item=item;// create newperson 赋值给当前item;
    }
    ListItem getNext(){
    return next;
    }
    ListItem getPrev(){
    return prev;
    }
    Person getItem(){
    return this.item;
    }
    void setNext(ListItem newNext){
    this.next=newNext;
    }
    boolean hasNext(){
    if(next!=null)return true;
    else return false;
    }
    boolean hasPrev(){
    if(prev!=null)return true;
    else return false;
    }
    public void setItem(Person item){
    this.item = item;
    }
    void setPrev(ListItem newPrev){
    this.prev=newPrev;
    }
    public String toString(){
    return item.toString();
    }

    }

  8. #8
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    package Test2;

    /*
    * Created on 2007-4-8
    *
    * TODO To change the template for this generated file go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    /**
    * @copyright
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class LinkedList {
    ListItem first;
    ListItem current;
    ListItem last;

    public LinkedList(){

    }

    public LinkedList(Person p){
    add(p);
    }

    public LinkedList(Person[] pA){

    for (int i = 0; i<pA.length; i++){
    add(pA[i]);
    }

    }

    public void add(Person newperson){
    ListItem newItem = new ListItem(newperson);//listitem consturctor;

    if (first==null){
    first = newItem;
    current = newItem;
    last = newItem;

    newItem.setPrev(null);
    newItem.setNext(null);
    } else {
    last.setNext(newItem);//找到最后一个点,last.next赋值,如同,*p指针的next指向newitem。
    newItem.setPrev(last);
    last = newItem;//链的最后一个元素为newitem;

    }
    }
    public boolean remove(Person person){
    boolean removeold=false;
    current=first;
    while(current!=last){

    if(current.item==person)
    {if(current == first) {
    first.getNext().setPrev(null);
    first = first.getNext();
    current = first;
    } else if (current == last){
    last.getPrev().setNext(null);
    last = last.getPrev();
    current = last;
    } else {
    current.getPrev().setNext(current.getNext());
    current.getNext().setPrev(current.getPrev());
    current = current.getNext();
    }
    removeold=true;break;


    }
    else {current=current.getNext();}
    }

    if(current==last&&current.item==person){
    removeold=true;
    if (last ==first){
    first = null;
    last = null;
    current = null;
    } else{
    last.getPrev().setNext(null);
    last = last.getPrev();
    current = last;
    } }
    return removeold;
    }
    public ListItem getFirst(){
    if (first!=null){
    current = first;
    return first;
    } else return null;
    }
    public ListItem getLast(){
    if (last!=null){
    current = last;
    return last;
    }
    else return null;
    }
    public ListItem getNext(){
    if (current.hasNext()){
    current = current.getNext();
    return current;
    } else
    return null;
    }
    public ListItem getPrev(){//yiqian de
    if (current.hasPrev()){
    current = current.getPrev();
    return current;
    } else
    return null;
    }

    public String toString(){
    String outString ="<TelephonVerzeichnis:>\n";
    ListItem nextItem = first;
    while (nextItem != null){
    outString += nextItem.toString()+"\n";
    nextItem = nextItem.getNext();
    }
    return outString + "</TelephonVerzeichnis:>\n";

    }
    }

  9. #9
    高级会员 新生儿 星星点 的头像
    注册日期
    2007-01-30
    住址
    shan shang de
    文章
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    声望力
    19

    预设 回复: 请教java编程问题!紧急!!!

    够哥们吧。。请客把

  10. #10
    TriVector
    游客

    预设 回复: 请教java编程问题!紧急!!!

    引用 作者: 星星点 查看文章
    CCNA kao de zen me yang le? wo zhi dao ni shi shui le.......zai code li bian ru zi ji de mingzi,ju shuo ni asp bu cuo, ni tong wu lai, jiu shi nage ai kan nü ren wo zui da de nage qing dao xiao di
    你下次回帖写德文或英文会不会更直接一些?。。。

主题讯息

目前查看此主题的会员

目前有1位用户正在查看此主题。(0 位会员和 1 游客)

发文规则

  • 不可以发表新主题
  • 不可以发表回复
  • 不可以上传附件
  • 不可以编辑自己的文章
  •