## chrisreaper's Profile User Rating:

Reputation: -1 Dishonored
Group:
Members
Active Posts:
26 (0.04 per day)
Joined:
27-September 11
Profile Views:
116
Last Active:
Feb 04 2013 05:15 PM
Currently:
Offline

### Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
AMD
Favorite Gaming Platform:
XBox
Who Cares
Dream Kudos:
0
chrisreaper has not set their status

### Posts I've Made

1. #### In Topic: Input and Output of Text Files

Posted 15 Nov 2011

Ah! I am dumb. I should've noticed that! I was fretting over nothing. Thank you very much. Final code, working!
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;

public class salaries
{
public static void main( String[] args ) throws Exception
{
// open the text file for reading with a Scanner

String[] ssn = new String[100]; // stores Social Security Number
double[] salaries = new double[100];
int[] years = new int[100];
int howmany = 0;

howmany = InputData (ssn, salaries, years);
Calculation(salaries, years, howmany);
Output(ssn, salaries, years, howmany);
}

public static int InputData(String[] social, double[] sal, int[] years) throws FileNotFoundException
{
Scanner input = new Scanner( new File( "salaries.txt" ) );
int i = 0;
while ( input.hasNext())
{
social[i] = input.next();

sal[i] = input.nextDouble();

years[i]  = input.nextInt();

i += 1;
}
input.close(); // close file
return i;

}
public static void Calculation(double[] sal, int[] years, int howmany)
{
for(int i = 0; i < howmany; i++)
{
if (years[i] >= 0 && years[i] <= 5)
sal[i] *= 1.03;
if (years[i] >= 6 && years[i] <= 10)
sal[i] *=1.04;
if (years[i] >= 11)
sal[i] *=1.05;
}
}
public static void Output(String[] social, double[] sal, int[] years, int howmany) throws FileNotFoundException
{
Formatter output = new Formatter("updated.txt");
for (int i = 0; i < howmany; i++)
{
output.format("SSN: %s ", social[i]);
output.format("New Salary: \$%.2f \r\n", sal[i]);

}
output.close();
}
}

2. #### In Topic: Input and Output of Text Files

Posted 15 Nov 2011

I changed that with my teachers help and now get this error
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
at java.util.Formatter\$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter\$FormatSpecifier.printFloat(Unknown Source)
at java.util.Formatter\$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at salaries.Output(salaries.java:57)
at salaries.main(salaries.java:19)
3. #### In Topic: Input and Output of Text Files

Posted 15 Nov 2011

Teacher told me to change a part:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;

public class salaries
{
public static void main( String[] args ) throws Exception
{
// open the text file for reading with a Scanner

String[] ssn = new String[100]; // stores Social Security Number
double[] salaries = new double[100];
int[] years = new int[100];
int howmany = 0;

howmany = InputData (ssn, salaries, years);
Calculation(salaries, years, howmany);
Output(ssn, salaries, years, howmany);
}

public static int InputData(String[] social, double[] sal, int[] years) throws FileNotFoundException
{
Scanner input = new Scanner( new File( "salaries.txt" ) );
int i = 0;
while ( input.hasNext())
{
social[i] = input.next();

sal[i] = input.nextDouble();

years[i]  = input.nextInt();

i += 1;
}
input.close(); // close file
return i;

}
public static void Calculation(double[] sal, int[] years, int howmany)
{
for(int i = 0; i < howmany; i++)
{
if (years[i] >= 0 && years[i] <= 5)
sal[i] *= 1.03;
if (years[i] >= 6 && years[i] <= 10)
sal[i] *=1.04;
if (years[i] >= 11)
sal[i] *=1.05;
}
}
public static void Output(String[] social, double[] sal, int[] years, int howmany) throws FileNotFoundException
{
Formatter output = new Formatter("updated.txt");
for (int i = 0; i < howmany; i++)
{
output.format("SSN is %f", social[i]);
output.format("New Salary is %f", sal[i]);
output.close();
}

}
}

still not working, new error message
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
at java.util.Formatter\$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter\$FormatSpecifier.printFloat(Unknown Source)
at java.util.Formatter\$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at salaries.Output(salaries.java:57)
at salaries.main(salaries.java:19)

4. #### In Topic: Input and Output of Text Files

Posted 15 Nov 2011

Current code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;

public class salaries
{
public static void main( String[] args ) throws Exception
{
// open the text file for reading with a Scanner

String[] ssn = new String[100]; // stores ssn
double[] salaries = new double[100];
int[] years = new int[100];
int howmany = 0;

howmany = InputData (ssn, salaries, years);
Calculation(salaries, years, howmany);
Output(ssn, salaries, years, howmany);
}

public static int InputData(String[] social, double[] sal, int[] years) throws FileNotFoundException
{
Scanner input = new Scanner( new File( "salaries.txt" ) );
int i = 0;
while ( input.hasNext())
{
social[i] = input.toString();

sal[i] = (double)input.nextDouble();

years[i]  = input.nextInt();

i += 1;
}
input.close(); // close file
return i;

}
public static void Calculation(double[] sal, int[] years, int howmany)
{
for(int i = 0; i < howmany; i++)
{
if (years[i] >= 0 && years[i] <= 5)
sal[i] *= 1.03;
if (years[i] >= 6 && years[i] <= 10)
sal[i] *=1.04;
if (years[i] >= 11)
sal[i] *=1.05;
}
}
public static void Output(String[] social, double[] sal, int[] years, int howmany) throws FileNotFoundException
{
Formatter output = new Formatter("updated.txt");
for (int i = 0; i < howmany; i++)
{
output.format("SSN is %f", social[i]);
output.format("New Salary is %f", sal[i]);
output.close();
}

}
}

I am wondering what is going on this this. This input file is attached at the bottom too.
5. #### In Topic: Input and Output of Text Files

Posted 14 Nov 2011

I really need help with this. fuzzy's idea still got me this. I am so confused about this
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at salaries.InputData(salaries.java:30)
at salaries.main(salaries.java:17)

### My Information

Member Title:
Age:
20 years old
Birthday:
December 12, 1992
Gender:
Location:
Findlay, OH
Interests:
Programming
Computer Science
Full Name:
Chris Reaper
Years Programming:
4
Programming Languages:
HTML, CSS, PHP, Java, Visual Basic

E-mail:
Private