⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cw2b.java

📁 samll awt programs for the beginner.
💻 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();
        
        //declare varialbe title and instantiate vector
        String title = "";
        Vector data=new Vector();
        double sum=0;
        Double myDouble;
        double datavalue; 
	
        
        
        //instantiate RandomAeccessFile. myData file is opened for reading
        try 
        {
            RandomAccessFile inFile=new RandomAccessFile(filename,"r");
            String line; //a string to contain the line read
            int lineNo=0;//initialise the line number of file
            
            // 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;
                 }// store the first line into title
                 
                 else
                 {
                    	myDouble=Double.valueOf(line);    //convert string to Integer
                    	datavalue=myDouble.doubleValue();  //get the int value of data
                    	sum=sum+datavalue;		  //do sum calculation
                   	data.addElement(myDouble);	//cast Integer to vector object
			
                 }// store the rest of file into vector data
		  
            
                lineNo++; //track line number to seperate the title input from vector input         
            }//end of while loop 
         }// end of try 
         catch (IOException e)
         {
            System.out.println("An i/o error has occured ["+e+"]");
         }// end of catch exception

      
         
         System.out.println("Title:"+"  "+title);// print out title
	 System.out.println("     "+"Data"+"     "+"Angle(degree)");//print out line of text

         
         // instatiate new vector angle and delacare new variables
        Double tmpValue;     		          // store temporary int variable
 	double value;           		  // primitive int value
	double angleDouble;      		  // primitive anlge int value
	int angleInt;
	Double myD;
	
	Vector angle=new Vector();	          // vector to contain angle 
	
         for(int n=0;n<data.size();n++)
         {
            
              tmpValue=(Double)data.elementAt(n);	//cast object from vector to Integer
              value=tmpValue.doubleValue();		//convert Integer to int
              angleDouble=Math.round(360*value/sum);	//caculate the angle
	      myD=new Double(angleDouble);
	      angleInt=myD.intValue();
				  
              angle.addElement(new Integer(angleInt));  /*convert int angle to Integer
							  cast Integer to vector object*/
                 
         
         }/* end of for loop */
	 
         //print out data in two vectors
	 for(int n=0;n<angle.size();n++)
	 {
	 	System.out.println("       "+((Double)data.elementAt(n)).intValue()+"       "+angle.elementAt(n));
	 }//end of for loop 
         
    }//end of public
}//end of class  
   
        
        
        
        
        
 

        
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -