//here is my code but whenever I compile and run the program, it gives me the first line in the //file
// here is the file:
//1,2,3,4,5,6,7
//2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36
//2513.45,1963.22,1568.35,1966.35,1893.25,1025.36,1128.36
//so how do I read the next line in this file
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Sales
{
double lab = 0;
private String FileName;
// getting the file
public Sales(String inFileName)
{
FileName = inFileName;
}
private Scanner keyboard = new Scanner(System.in);
public Sales ()
{
//calling the topOfPageInfo method
topOfPageInfo();
}
public static void topOfPageInfo()
{
final String MY_NAME = "sheharyar Alam";
final String DASHES = "---------------------------------------------------";
System.out.println ("\t" + DASHES + "\n\t\t\tName: " + MY_NAME);
System.out.println ("\t\t\tlab #: 1");
System.out.println ("\t\t\tDue Date: 01/31/2008");
GregorianCalendar today = new GregorianCalendar();
DecimalFormat twoDigits = new DecimalFormat ("00");
System.out.println ("\n\t\t\tToday's Date: "
+ twoDigits.format(today.get(Calendar.MONTH)+1)
+ '/' +twoDigits.format(today.get(Calendar.DAY_OF_MONTH))
+ '/' +twoDigits.format(today.get(Calendar.YEAR)));
System.out.println("\t\t\tAnd Time Now is: " + twoDigits.format(today.get(Calendar.HOUR))
+ ':' + twoDigits.format(today.get(Calendar.MINUTE))
+ ':' +twoDigits.format(today.get(Calendar.SECOND)));
System.out.println("\t" + DASHES + "\n");
}
public void readData() throws IOException
{
int i=0;
// opening the file
String inFile = "SalesData.txt";
try
{
Scanner x = new Scanner(new File (inFile));
String week1 = x.next();
// token(sales1) printed with dilimeters
StringTokenizer st = new StringTokenizer(week1,",");
week1 = x.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(week1,",");
Scanner y = new Scanner(new File (inFile));
String week2 = y.next();
StringTokenizer stg = new StringTokenizer(week2,",");
week2= y.next();
// tokens(sales2) printed without dilimeters
StringTokenizer sti = new StringTokenizer(week2,",");
while( str.hasMoreTokens())
{ String totsales = str.nextToken();
lab = lab + Double.parseDouble(totsales);
i++;
}
System.out.println(" Week #1 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 1:" + week1);
System.out.println("");
System.out.println("Total Sales for Week 1 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 1 = "+"$"+lab/7);
System.out.println("");
System.out.println("----------------------------------------------------------------------");
System.out.println(" Week #2 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 2:" + week2);
System.out.println("");
System.out.println("Total Sales for Week 2 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 2 = "+"$"+lab/7);
System.out.println("");
System.out.println("------------------------------------------------------------------------------");
System.out.println(" Summary ");
System.out.println(" ---------");
System.out.println("");
System.out.println(" Number of Weeks Data Processed ="+"$");
System.out.println("");
System.out.println(" Total Sales for all Week ="+"$");
System.out.println(" Average Weekly Sales ="+"$");
}
catch(Exception a)
{
System.out.println("File not found");
}
}
}
// here is the file:
//1,2,3,4,5,6,7
//2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36
//2513.45,1963.22,1568.35,1966.35,1893.25,1025.36,1128.36
//so how do I read the next line in this file
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Sales
{
double lab = 0;
private String FileName;
// getting the file
public Sales(String inFileName)
{
FileName = inFileName;
}
private Scanner keyboard = new Scanner(System.in);
public Sales ()
{
//calling the topOfPageInfo method
topOfPageInfo();
}
public static void topOfPageInfo()
{
final String MY_NAME = "sheharyar Alam";
final String DASHES = "---------------------------------------------------";
System.out.println ("\t" + DASHES + "\n\t\t\tName: " + MY_NAME);
System.out.println ("\t\t\tlab #: 1");
System.out.println ("\t\t\tDue Date: 01/31/2008");
GregorianCalendar today = new GregorianCalendar();
DecimalFormat twoDigits = new DecimalFormat ("00");
System.out.println ("\n\t\t\tToday's Date: "
+ twoDigits.format(today.get(Calendar.MONTH)+1)
+ '/' +twoDigits.format(today.get(Calendar.DAY_OF_MONTH))
+ '/' +twoDigits.format(today.get(Calendar.YEAR)));
System.out.println("\t\t\tAnd Time Now is: " + twoDigits.format(today.get(Calendar.HOUR))
+ ':' + twoDigits.format(today.get(Calendar.MINUTE))
+ ':' +twoDigits.format(today.get(Calendar.SECOND)));
System.out.println("\t" + DASHES + "\n");
}
public void readData() throws IOException
{
int i=0;
// opening the file
String inFile = "SalesData.txt";
try
{
Scanner x = new Scanner(new File (inFile));
String week1 = x.next();
// token(sales1) printed with dilimeters
StringTokenizer st = new StringTokenizer(week1,",");
week1 = x.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(week1,",");
Scanner y = new Scanner(new File (inFile));
String week2 = y.next();
StringTokenizer stg = new StringTokenizer(week2,",");
week2= y.next();
// tokens(sales2) printed without dilimeters
StringTokenizer sti = new StringTokenizer(week2,",");
while( str.hasMoreTokens())
{ String totsales = str.nextToken();
lab = lab + Double.parseDouble(totsales);
i++;
}
System.out.println(" Week #1 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 1:" + week1);
System.out.println("");
System.out.println("Total Sales for Week 1 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 1 = "+"$"+lab/7);
System.out.println("");
System.out.println("----------------------------------------------------------------------");
System.out.println(" Week #2 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 2:" + week2);
System.out.println("");
System.out.println("Total Sales for Week 2 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 2 = "+"$"+lab/7);
System.out.println("");
System.out.println("------------------------------------------------------------------------------");
System.out.println(" Summary ");
System.out.println(" ---------");
System.out.println("");
System.out.println(" Number of Weeks Data Processed ="+"$");
System.out.println("");
System.out.println(" Total Sales for all Week ="+"$");
System.out.println(" Average Weekly Sales ="+"$");
}
catch(Exception a)
{
System.out.println("File not found");
}
}
}