在Java中使用多个类创建程序时遇到的类问题
我正在尝试创建一个程序,其中用户输入四位数字,并给出一个六位数字。前四位是用户输入的数字,第五位是((digit1+digit2+digit4)%10),第六位是第三位。这是我到目前为止所拥有的。已提供用于用户输入的类。感谢您的帮助
import java.lang.Math;
/**
* Purpose: This class/program generates a 6 digit card number based on 4 digits inputed by the user
*/
public class CardGenerator
{
public void main(String[] args)
{
UserInteraction input = new UserInteraction();
calculateDigit5 digit5Calc = new calculateDigit5();
getDigit digit = new getDigit();
getRemainder remainder = new getRemainder();
int number = input.getIntValueFromUser("Enter the four digit card number"),
digit1 = getDigit(number, 3),
number = getRemainder(number, 3),
digit2 = getDigit(number, 2),
number = getRemainder(number, 2),
digit3 = getDigit(number, 1),
number = getRemainder(number, 1),
digit4 = getDigit(number, 0),
digit5 = calculateDigit5,
digit6 = digit3;
System.out.println("The 6 digit card number is " + digit1 + digit2 + digit3 + digit4 + digit5
+ digit6);
}
public class getDigit
{
int digitWeight = Math.pow(number, (1/1000)),
rem = getRemainder(number, digitPosition),
digit = (originalNumber - rem) / digitWeight;
}
public class getRamainder
{
}
public class calculateDigit5
{
int digit5 = (digit1 + digit2 + digit4) % 10;
}
}
这是提供给我的
import java.util.*;
//DO NOT PUT OTHER METHODS IN THIS CLASS or make any changes to it
public class UserInteraction
{
public String getStringValueFromUser(String message)
{
String value = "";
Scanner input = new Scanner(System.in);
System.out.print(message + " : ");
value = input.nextLine();
return value;
}
//DO NOT PUT OTHER METHODS IN THIS CLASS or make any changes to it
public double getDoubleValueFromUser(String message)
{
double value = 0;
Scanner input = new Scanner(System.in);
System.out.print(message + " : ");
value = input.nextDouble();
return value;
}
//DO NOT PUT OTHER METHODS IN THIS CLASS or make any changes to it
public int getIntValueFromUser(String message)
{
int value = 0;
Scanner input = new Scanner(System.in);
System.out.print(message + " : ");
value = input.nextInt();
return value;
}
//DO NOT PUT OTHER METHODS IN THIS CLASS or make any changes to it
}
# 1 楼答案
这应该足以让你开始。有无数种方法可以做到这一点,但这是我的实现