sheharyar alam

Greenhorn
+ Follow
since Mar 04, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sheharyar alam

//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");

}
}


}
14 years ago
I am trying to do the following: If you guys can help, that would be great

PART I

1. the total sales for each week?
2. the average daily sales for each week?
3.The total sales for all the week?
4.the average weekly sales?

PART II

readText(): Read text line-by-line and print it as it appears in the given data file, also print number of line read from the data file?

storeTokens(): open file again, read the whole line and tokenize it; and store tokens in an array
of strings (call it words or tokens array). the punctuation marks may be a comma, semicolon, question mark, colon, or a period (',' ':', ';', '.').

printToken(): print all extracted words; 10 words to a line. Also print the total number of words stored in the array.

alphabetizeTokens(): alphabetize the words and again print them using printToken() method mentioned above. Print 10 words to a line again.

doFrequency(); compute frequency and print each unique word along with its frequency in the
data file under appropriate headings as shown in the sample output. Number the output lines.

AND SO FAR I HAVE THE FOLLOWING CODE :

// this is for part I service class, in this class all I need to do is some how do the summary:
// number of weeks data processed:
//total sales for all weeks:
//average weekly sales:


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");

}
}


}

PART II

// I have the service class but its not doing what I want it to do
//readText()
//storeTokens()
//printToken()
//alphabetizeToken()
//doFrequency()

import java.util.StringTokenizer;
import java.io.*;
import java.util.*;

public class TokenS
{
double lab = 0;

private String FileName;
// getting the file
public TokenS(String inFileName)
{
FileName = inFileName;
}
public TokenS()
{
}

public void readText() throws IOException
{
int i = 0;

String inFile = "sample.txt";

try
{
Scanner Tokens = new Scanner(new File (inFile));
String Token = Tokens.next();
// token(sales1) printed with dilimeters
StringTokenizer st = new StringTokenizer(Token,",");
Token = Tokens.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(Token,",");

while( str.hasMoreTokens())
{ String totsales = str.nextToken();

lab = lab + Double.parseDouble(totsales);

i++;
}

System.out.println(" Number of Lines Read = 4 ");
System.out.println("_____________________________________________");
System.out.println("");
System.out.println(" All Words without Punctuation Marks ");
System.out.println(Token);
}

catch(Exception a)
{
System.out.println("File not found");

}

}
}

AND SO HERE THE MAIN CLASS (CLIENT CLASS)

import java.util.Scanner;
import java.io.*;

public class SalesS
{
public static void main (String[] args) throws IOException
{
Sales mysale = new Sales();
//mysale.topOfPageInfo();
mysale.readData();

TokenS mytoken = new TokenS();
mytoken.readText();

}
14 years ago
hey guys, if someone can help me on this program, it would be great

I am trying to do the following:

PART I

1. the total sales for each week?
2. the average daily sales for each week?
3.The total sales for all the week?
4.the average weekly sales?

PART II

readText(): Read text line-by-line and print it as it appears in the given data file, also print number of line read from the data file?

storeTokens(): open file again, read the whole line and tokenize it; and store tokens in an array
of strings (call it words or tokens array). the punctuation marks may be a comma, semicolon, question mark, colon, or a period (',' ':', ';', '.').

printToken(): print all extracted words; 10 words to a line. Also print the total number of words stored in the array.

alphabetizeTokens(): alphabetize the words and again print them using printToken() method mentioned above. Print 10 words to a line again.

doFrequency(); compute frequency and print each unique word along with its frequency in the
data file under appropriate headings as shown in the sample output. Number the output lines.

AND SO FAR I HAVE THE FOLLOWING CODE :

// this is for part I service class, in this class all I need to do is some how do the summary:
// number of weeks data processed:
//total sales for all weeks:
//average weekly sales:


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");

}
}


}

PART II

// I have the service class but its not doing what I want it to do
//readText()
//storeTokens()
//printToken()
//alphabetizeToken()
//doFrequency()

import java.util.StringTokenizer;
import java.io.*;
import java.util.*;

public class TokenS
{
double lab = 0;

private String FileName;
// getting the file
public TokenS(String inFileName)
{
FileName = inFileName;
}
public TokenS()
{
}

public void readText() throws IOException
{
int i = 0;

String inFile = "sample.txt";

try
{
Scanner Tokens = new Scanner(new File (inFile));
String Token = Tokens.next();
// token(sales1) printed with dilimeters
StringTokenizer st = new StringTokenizer(Token,",");
Token = Tokens.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(Token,",");

while( str.hasMoreTokens())
{ String totsales = str.nextToken();

lab = lab + Double.parseDouble(totsales);

i++;
}

System.out.println(" Number of Lines Read = 4 ");
System.out.println("_____________________________________________");
System.out.println("");
System.out.println(" All Words without Punctuation Marks ");
System.out.println(Token);
}

catch(Exception a)
{
System.out.println("File not found");

}

}
}

AND SO HERE THE MAIN CLASS (CLIENT CLASS)

import java.util.Scanner;
import java.io.*;

public class SalesS
{
public static void main (String[] args) throws IOException
{
Sales mysale = new Sales();
//mysale.topOfPageInfo();
mysale.readData();

TokenS mytoken = new TokenS();
mytoken.readText();

}
14 years ago
hello guys

I am new at this stuff, so I am trying to learn this java stuff lol,

but anyway

My qustion is how do I Read text line by line and print it as it appears in the given data file
14 years ago