java - 如何用 Java 中表上的特定索引替换文本?

标签 java

我目前有一个用于管理商店的学校项目,但我真的不知道如何进行此替换。变量名称目前采用我的母语。这是编辑部分:

public static void Modify() { 
    String mod=JOptionPane.showInputDialog("Input the id code of the seller you want to modify: "); 
    int mod1 = new Integer(mod).intValue(); 
    while (i == mod1){ 
        Store.setName(getName()); 
        Store.setSurname(surname); 
        Store.setId(getID()); 
        Store x=new Store(getName(), surname, getID()); 
        Info[i]=x; 
        System.out.println("Registered seller "+ getName() +" "+ surname);
    }
}

我这样做是为了通过它进行搜索,但不起作用:

public static void Search(){
    String code1= JOptionPane.showInputDialog("Input the code of the seller you are searching for: ");
    int code = new Integer(code1).intValue();
    String answer = Store.getName();
    for (int i=0; i<numri;i++){
        if (Store.getID()==code)
        {
            answer=Store.getName();
            System.out.println("The seller you are looking for is: " + answer);
        }
        else 
            System.out.println("The seller you are looking for cannot be found");
        break;
    }
}

它只打印最后一个。

这是完整的代码:

import javax.swing.JOptionPane;

public class Store{
    private static String name;
    public static String surname;
    private static int ID;

  static String nr = JOptionPane.showInputDialog("Input the number of sellers you want to register: ");
static int number=new Integer(nr).intValue();

 static Store[] Info = new Store[number];
private static int i;
//Input of info
public Store(String name, String surname, int id) {

    }
public static void setName(String namee){
    String e = JOptionPane.showInputDialog("Write the sellers name: ");
    setname(e);
}
public static void setSurname(String surnamee){
    String m = JOptionPane.showInputDialog("Write the sellers surname: ");
    surname=m;
}
public static void setId(int ID){
    String ID1 = JOptionPane.showInputDialog("Input the id code of the seller: ");
    int Id=new Integer(ID1).intValue();
    ID=Id;
}

public static void FillTable() //Registering sellers
{for (int i =0; i<number; i++){
    Store.setName(getName());
    Store.setSurname(surname);
    Store.setId(getID());
    Store x=new Store(getName(), surname, getID());
    Info[i]=x;
    System.out.println("Registered seller "+ getname() +" "+ surname);}}

//Search
public static void Search(){
    String code1= JOptionPane.showInputDialog("Write the code of the seller you want to find: ");
    int code = new Integer(code1).intValue();
    String answer = Store.getName();
    for (int i=0; i<number;i++){
        if (Store.getID()==code)
        {answer=Store.getname();
        System.out.println("The seller you are searching for is: " + answer);
        break;
        }
        else System.out.println("The seller cannot be found.");
        break;
        }


}

// Modifying the sellers
public static void Modify(){
String mod=JOptionPane.showInputDialog("Write the code of the seller you want to modify: ");
 int mod1 = new Integer(mod).intValue();
 while (i == mod1){
     Store.setName(getname());
        Store.setSurname(surname);
        Store.setId(getID());
        Store x=new Store(getName(), surname, getID());
        Info[i]=x;
        System.out.println("Edited seller "+ getName() +" "+ surname);}}




private static void remove(int f) {
    // TODO Auto-generated method stub

}
public static void main(String[] args) {
    Store.FillTable();
    Store.Search();
    Store.Modify();
    }
public static int getID() {
    return ID;
}
public static void setID(int iD) {
    ID = iD;
}
public static String getName() {
    return name;
}
public static void setName(String name) {
    Store.name = name;
}

}

最佳答案

字符串的Java国际化可以通过ResourceBundle来完成类(class)。使用时的简单示例:

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("ApplicationMessages", Locale.FRANCE);
    System.out.println(bundle.getString("CountryName"));
    System.out.println(bundle.getString("CurrencyCode"));
}

这是一个简短的tutorial关于如何开始使用它,您可以谷歌搜索更多示例。它很容易使用,但要小心 - 也很容易意外地漏掉一个区域设置的字符串。

关于java - 如何用 Java 中表上的特定索引替换文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35162105/

相关文章:

java - 如何将整数转换为 A1 表示法?

java - JAVA/C++ 中尾随字符的使用

java - Map 中存储的每个对象都会返回最后一个对象中存储的值

java - 尝试在 Java 中加载 json 文件时出现 NPE

java - 如何获取 Java 数组对象的大小 O(1)?

java - 如何在运行时访问另一个项目中的类

java - Java 基本类型的包装器

java - 将 Java 转换为 iOS

java - 使用可变大小数据按类型和日期对对象列表进行排序和分组

java - Junit 和消息框