所以我正在做这个项目,我无法将变量从一个类移动到另一个类。这个小软件的目标是让用户输入两条信息,一条是字符串,另一条是整数。我还有 2 个类,一个用于检索信息,另一个用于计算信息。这是名为 Software 的第一类:
import java.util.Scanner;
public class Software
{
public Scanner softwareName;
public Scanner devicesAmount;
public Software()
{
devicesAmount = new Scanner(System.in);
softwareName = new Scanner(System.in);
}
/**
*Gets the information from the user to later on process
*/
public void InfoGet()
{
Devices findDevices= new Devices();
Devices findNumber= new Devices();
String softwareName;
int devicesAmount;
Scanner sc= new Scanner(System.in);
System.out.println("Welcome to the Software License Calculator");
System.out.println("Please type in the name of the Software:");
softwareName = sc.nextLine();
System.out.println("");
System.out.println("Please type in the number of devices that have the software:");
devicesAmount=sc.nextInt();
findDevices.Calculations(devicesAmount);
findNumber.getNewDevices();
sc.close();
System.out.println(softwareName+ " & "+ findNumber);
}
}
这是第二类,称为设备:
public class Devices
{
public int NewDevices;
public String softwareName;
/**
* Gets number of Devices to preform the calculations of removing 1000 users
*/
public static void Devices()
{
Software getDevices= new Software();
getDevices.InfoGet();
}
public void Calculations(int devicesAmount){
if (devicesAmount>=1000){
NewDevices= devicesAmount - 1000;
}
else{
NewDevices=devicesAmount;
}
}
}