?? cw2b.java
字號:
/**
* Author: Jing Han
* Date; 12/11/03
*Module: G6DICp
* Title: ICP Coursework 2
* SCSiT Username: jxh23m
*/
import java.util.*;
import java.io.*;
class cw2b
{
public static void main(String[] arg)
{
//prompt for filename
System.out.print("Enter data file:"+" ");
String filename=TButils.readln();
String title = "";
Vector data=new Vector();
double sum=0;
Double myDouble;
double datavalue;
/*----------------------------------------------------------------------
*read the file data into title and vector
*covert string line into int number and get double value of data
*sum calculation
*cast double number into Integer and put into vector
*---------------------------------------------------------------------*/
try
{
RandomAccessFile inFile=new RandomAccessFile(filename,"r");
String line;
int lineNo=0;
/* use the readLine method to read a line into the string line
*until the end of the file*/
while((line=inFile.readLine())!=null)
{
if( lineNo == 0 )
{
title=line;
}
else
{
String newline=line.trim(); //trim leading spaces from line
myDouble=Double.valueOf(newline);
datavalue=myDouble.doubleValue();
sum=sum+datavalue;
data.addElement(myDouble);
}
lineNo++;
}
}
catch (IOException e)
{
System.out.println("An i/o error has occured ["+e+"]");
}
System.out.println("Title:"+" "+title);
System.out.println();
System.out.println();
// instatiate new vector angle and delacare new variables
Double tmpValue;
double value;
int angleInt;
Double myD;
double angleDouble;
Vector angle=new Vector();
/*-------------------------------------------------------------------------
*cast data in the vector to Integer
*get data int value and convert to double
*calculate double angle and get the int value of angle
*cast double angle to Integer and store into new vector
*--------------------------------------------------------------------------*/
for(int n=0;n<data.size();n++)
{
tmpValue=(Double)data.elementAt(n);
value=tmpValue.doubleValue();
angleDouble=Math.round(360*value/sum);
myD=new Double(angleDouble);
angleInt=myD.intValue();
angle.addElement(new Integer(angleInt));
}
//print out line of words and data
{
System.out.println(" "+"Data"+" "+"Angle(degree)");
}
for(int n=0;n<data.size();n++)
{
System.out.println(" "+((Double)data.elementAt(n)).intValue()+" "+angle.elementAt(n));
}
}
}//end of class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -