gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:58:27 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com