Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Arrays

  Asked By: Bastet    Date: Apr 22    Category: Java    Views: 685
  

I have this assignment that is over a week
due and I have test due. Panic! Anyhow, here is the code. If some
could just take a look at it and tell me why it not working that
would be awesome. I know my code is awful, so don't worry about
being too critical.

import cs1.Keyboard;
import java.text.*;
import java.text.NumberFormat;

public class Foreign
{
private static int country;
private static int index = 0, count = 0;
private double dollars, conversion;
private static double[] Rates = {1.31372,11.4140,108.485,0.81209 };
private static String[] Countries = {"Canadian Dollar", "Mexican
Peso", "Japanese Yen", "Greek Drachma"};


public Foreign()
{
int[] country = new int[4];
double[] conversion = new double[4];
DecimalFormat money = new DecimalFormat("$0.##");
}

public static void title()
{
System.out.println("\t==================");
System.out.println("\tForeign Exchange \n");
}

public static void display()
{
System.out.println("\tThe total number of conversions are " + count);
}

public void getConversion_rates()
{
double[] dollars = new double[4];
for (int i=0; i<4; i++) System.out.println(i+1 + "\tU.S. Dollars
to " + "\"" + Countries[i] + "\"");
{
System.out.print("\nSelect the appropriate currency 1-4: \t");
for (int index = 0; index < 4; index++)
country = Keyboard.readInt();//fills 4

for (int country; index < 5; index ++); // use count to count country
System.out.println(Rates[index]);

count++;
}
}

public void print()
{
DecimalFormat money = new DecimalFormat("$0.##");
NumberFormat fmt = NumberFormat.getCurrencyInstance();

System.out.println("");
System.out.println("Country:=\t" + Countries[country-1]);
System.out.println("Rate: =\t=\t" + money.format(Rates[country-1]));
System.out.println("Dollars:=\t" + fmt.format(dollars));
System.out.println("Value: \t=\t" + money.format(conversion));
System.out.println("");
}

public String toString()
{
String line;
NumberFormat fmt = NumberFormat.getCurrencyInstance();
line = Countries[country-1] + " " + Rates[country-1] + " " +
fmt.format(dollars) + " " + fmt.format(conversion);
return line;
}
}

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Baylen Smith     Answered On: Apr 22

can someone proofread what's wrong with this, and tell me please??!


public class Arrays
{

public static void main(String[] args)
{
int []z = {-1, -5, -2, 5, 3, 4, 9, 7, 8, -9}; //listing
initializing
int []even = new int[10];
int []nonpositive = new int[10];
int []odd = new int[10];

even(z, even);
odd(z, odd);
nonpositive(z, nonpositive);

int SizeEven;
int SizeNonpositive;
int SizeOdd;

SizeEven = even(z,even);
DisplayEven(even, SizeEven);

SizeOdd = odd(z,odd);
DisplayOdd(odd,SizeOdd);

SizeNonpositive = nonpositive(z,nonpositive);
DisplayNonpositive(nonpositive, SizeNonpositive);
}

public static int even (int []z, int[]even) //Set codes for even
arrays
{
int q;
int r = 0;
for(q = 0; q < z.length; q++){
if (z[q]%2== 0){
even[r]=z[q];
r++;
}
}
return r;
}

public static void DisplayEven (int []even, int[]
SizeEven) //Display even numbers
{
int i;
for (i = 0; i < SizeEven; i++){
System.out.println (even[i] + " " );
}

System.out.println();
}


public static int odd (int []z, int[]odd) //Set codes for odd arrays
{
int s;
int t = 0;

for(s = 0; s < z.length; s++){
if (z[s]%2!= 0){
odd[t]=z[s];
t++;
}
}
return t;
}

public static void DisplayOdd (int []odd, int[]SizeOdd) //Display
odd numbers
{
int i;
for (i = 0; i < SizeOdd; i++){
System.out.println (odd[i] + " " );
}
System.out.println();
}

public static int nonpositive (int []z, int[]nonpositive) //Set
codes for negative arrays
{
int s;
int t = 0;

for (s = 0; s < z.length; s++){
if (z[s] < 0){
nonpositive[t] =z[s];
t++;
}
}
return t;
}

public static void DisplayNonpositive (int[]nonpositive, int[]
SizeNonpositive) //Display negative numbers
{
int i;
for (i = 0; i < SizeNonpositive; i++){
System.out.println (nonpositive[i] + " " );
}
System.out.println();
}
}


 
Answer #2    Answered By: Lughaidh Fischer     Answered On: Apr 22

Check the following methods carefully , then u will understand by urself
...



public static void DisplayNonpositive(int[] nonpositive,int[]
SizeNonpositive)

public static void DisplayOdd(int[] odd, int[] SizeOdd)

public static void DisplayEven(int[] even, int[] SizeEven)

 
Didn't find what you were looking for? Find more on Arrays Or get search suggestion and latest updates.




Tagged: