나는 먼저 어떤 카드를 지불해야하는지 알려주는 신용 카드 프로그램을 작성 중입니다. 모든 카드는 사용자로부터 읽혀집니다. 가장 큰 이자율로 카드를 표시하는 방법을 찾지 못하는 것 같습니다.Java에서 배열의 특정 요소를 어떻게 표시합니까?
나는 findHighestRate라는 메서드를 설정했으며, 사용자가 입력 한 최고 이자율을 찾고 배열을 살펴 보는 것이 그 일이라고 생각합니다. 이제 나는 코드의 일부가 정확하다고 믿지만, 내 디스플레이 방법 (차트의 모든 사용자 입력을 표시)을 통해 가장 높은 값을 표시하기 위해 무수히 많은 노력을했지만 항상 매번 짧은 시간을 보냈습니다.
public static void header()
{
System.out.printf("%9s %22s %24s %29s" , "Card" , "Rate of Interest" , "Current Amount Owed", "Amount owed in One Year");
System.out.println();
System.out.print("============================");
System.out.print("=================================================================");
System.out.print("=====");
}
public static void display (String card [], double rOI [], double current [], double owed1yr [], int i)
{
System.out.printf("\n%11s %14.2f %25.2f %25.2f" , card[i], rOI[i], current[i], owed1yr[i]);
}
public static String getString (String s)
{
Scanner keyIn = new Scanner (System.in);
//prompt
System.out.print(s+": ");
return keyIn.nextLine().trim();
}
public static int findHighestRate(double interestRate [], int index)
{
double max = 0;
index = -1;
for (int i = 0; i < interestRate.length; i++)
if (interestRate[i] > max){
max = interestRate[i];
index = i;
}
return index;
}
public static double getDouble(String s)
{
Scanner stdIn = new Scanner (System.in);
// Prompt the user for the string needed
System.out.print(s+": ");
return stdIn.nextDouble();
}
public static void main (String [] args)
{
//bringing arrays to life.
String [] c = new String [4];
double [] rateOfInterest = new double [4];
double [] currentAmountOwed = new double [4];
double [] yr1Owed = new double [4];
int index =0;
intro();
System.out.println("Please enter the name of the card, interest rate, and amount owed");
for (int i = 0; i <c.length; i++){
System.out.println();
c[i] = getString ("Card");
rateOfInterest [i] = getDouble("Rate of interest");
currentAmountOwed [i] = getDouble ("Amount Owed");
}
System.out.println();
for (int i =0 ; i < c.length; i++){
yr1Owed[i] = ((rateOfInterest[i] * currentAmountOwed[i] /100) + currentAmountOwed[i]);
}
header();
for (int i = 0; i <c.length; i++)
{
display(c, rateOfInterest, currentAmountOwed,yr1Owed, i );
}
System.out.println();
System.out.println();
System.out.println("Seach for the highest rate of interest.. Pay this off first");
System.out.println();
header();
for (int i = 0; i <c.length; i++)
{
FIND HIGHEST RATE METHOD HERE
}
//highest rate part of code not included..... did not complete.
}
}
당신은이 그 값을 출력 할 수있는 배열의 요소에 액세스 할 그 변수의 값을 사용할 수 있습니다
를 들어
'findHighestRate' 메소드. 왜 그걸 부르지 않는거야? 왜 그것은'index' 매개 변수를 가지고 있습니까? 왜 지금 수정하고 있니? –
내가 가장 높은 비율을 인쇄해야하기 때문에 아무것도 인쇄하지 않을 것입니다. 매개 변수로 전달되는 인덱스의 경우 배열의 place holder가 맞습니까? –
'findHighestRate'는 뭔가를 반환합니다. 그 가치는 무엇입니까? 그것이 무엇을 나타내는가? 어떻게 배열 요소에 접근합니까? 액세스 할 수 있으면 인쇄 할 수 없습니까? array_ **의 의미는 무엇입니까 **? 바로 수정하려면 발신자가 제공하는 것이 무엇입니까? –