/**I have posted the txt file as well but if i doesnot show up it is as below
Moretti 407 S 5.7
Lauscha 335 O 8.6
Vertroford 907 L 2.1
name, type number, type of glass, ounces (16 ounces = 1 pound).
S (special) = $10 per pound
O (opaque) = $12 per pound
L (Odd Lot) = $45 per pound
*/
import java.io.*;
import java.util.Scanner;
public class GlassCost
{
public static void main (String[] args)throws IOException
{
String input, str, name;
int num;
char letter;
double ounces, cost;
Scanner keyboard = new Scanner (System.in);
System.out.println("File name: ");
input = keyboard.nextLine();
Scanner inFile = new Scanner (new FileReader ("and.txt"));
name = inFile.nextLine();
num = inFile.nextInt();
while(inFile.hasNext())
{
letter = inFile.charAt(name);
ounces = inFile.nextDouble();
switch (letter)
{
case S:
cost = (ounces/ 16) * 15;
System.out.println(name + " uses Special costing: " + cost);
break;
case O:
cost = (ounces/ 16) * 12;
System.out.println(name + " uses Special costing: " + cost);
break;
case L:
cost = (ounces/ 16) * 45;
System.out.println(name + " uses Special costing: " + cost);
break;
}
}
inFile.close();
}
}
//I just need help to read the file properply please help
*Edit: Please use code tags in the future, thanks!
Attached File(s)
-
and.txt (58bytes)
Number of downloads: 56
This post has been edited by Martyr2: 17 October 2009 - 10:25 AM

New Topic/Question
Reply




MultiQuote




|