anonymous No title
Java
/*
 [The "BSD license"]
  Copyright (c) 2013 Terence Parr
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products
     derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DiagnosticErrorListener;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.gui.Trees;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.File;
import java.lang.System;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/* This more or less duplicates the functionality of grun (TestRig) but it
 * has a few specific options for benchmarking like -x2 and -threaded.
 * It also allows directory names as commandline arguments. The simplest test is
 * for the current directory:

~/antlr/code/grammars-v4/java $ java Test .
/Users/parrt/antlr/code/grammars-v4/java9/JavaBaseListener.java
/Users/parrt/antlr/code/grammars-v4/java9/Java9Lexer.java
/Users/parrt/antlr/code/grammars-v4/java9/JavaListener.java
/Users/parrt/antlr/code/grammars-v4/java9/JavaParser.java
/Users/parrt/antlr/code/grammars-v4/java9/Test.java
Total lexer+parser time 1867ms.
 */
class Test {
//	public static long lexerTime = 0;
	public static boolean profile = false;
	public static boolean notree = false;
	public static boolean gui = false;
	public static boolean printTree = false;
	public static boolean SLL = false;
	public static boolean diag = false;
	public static boolean bail = false;
	public static boolean x2 = false;
	public static boolean threaded = false;
	public static boolean quiet = false;
//	public static long parserStart;
//	public static long parserStop;
	public static Worker[] workers = new Worker[3];
	static int windex = 0;

	public static CyclicBarrier barrier;

	public static volatile boolean firstPassDone = false;

	public static class Worker implements Runnable {
		public long parserStart;
		public long parserStop;
		List<String> files;
		public Worker(List<String> files) {
			this.files = files;
		}
		@Override
		public void run() {
			parserStart = System.currentTimeMillis();
			for (String f : files) {
				parseFile(f);
			}
			parserStop = System.currentTimeMillis();
			try {
				barrier.await();
			}
			catch (InterruptedException ex) {
				return;
			}
			catch (BrokenBarrierException ex) {
				return;
			}
		}
	}

	public static void main(String[] args) {
		doAll(args);
	}

	public static void doAll(String[] args) {
		List<String> inputFiles = new ArrayList<String>();
		long start = System.currentTimeMillis();
		try {
			if (args.length > 0 ) {
				// for each directory/file specified on the command line
				for(int i=0; i< args.length;i++) {
					if ( args[i].equals("-notree") ) notree = true;
					else if ( args[i].equals("-gui") ) gui = true;
					else if ( args[i].equals("-ptree") ) printTree = true;
					else if ( args[i].equals("-SLL") ) SLL = true;
					else if ( args[i].equals("-bail") ) bail = true;
					else if ( args[i].equals("-diag") ) diag = true;
					else if ( args[i].equals("-2x") ) x2 = true;
					else if ( args[i].equals("-threaded") ) threaded = true;
					else if ( args[i].equals("-quiet") ) quiet = true;
					if ( args[i].charAt(0)!='-' ) { // input file name
						inputFiles.add(args[i]);
					}
				}
				List<String> javaFiles = new ArrayList<String>();
				for (String fileName : inputFiles) {
					List<String> files = getFilenames(new File(fileName));
					javaFiles.addAll(files);
				}
				doFiles(javaFiles);

//				DOTGenerator gen = new DOTGenerator(null);
//				String dot = gen.getDOT(Java9Parser._decisionToDFA[112], false);
//				System.out.println(dot);
//				dot = gen.getDOT(Java9Parser._decisionToDFA[81], false);
//				System.out.println(dot);

				if ( x2 ) {
					System.gc();
					System.out.println("waiting for 1st pass");
					if ( threaded ) while ( !firstPassDone ) { } // spin
					System.out.println("2nd pass");
					doFiles(javaFiles);
				}
			}
			else {
				System.err.println("Usage: java Main <directory or file name>");
			}
		}
		catch(Exception e) {
			System.err.println("exception: "+e);
			e.printStackTrace(System.err);   // so we can get stack trace
		}
		long stop = System.currentTimeMillis();
//		System.out.println("Overall time " + (stop - start) + "ms.");
		System.gc();
	}

	public static void doFiles(List<String> files) throws Exception {
		long parserStart = System.currentTimeMillis();
//		lexerTime = 0;
		if ( threaded ) {
			barrier = new CyclicBarrier(3,new Runnable() {
				public void run() {
					report(); firstPassDone = true;
				}
			});
			int chunkSize = files.size() / 3;  // 10/3 = 3
			int p1 = chunkSize; // 0..3
			int p2 = 2 * chunkSize; // 4..6, then 7..10
			workers[0] = new Worker(files.subList(0,p1+1));
			workers[1] = new Worker(files.subList(p1+1,p2+1));
			workers[2] = new Worker(files.subList(p2+1,files.size()));
			new Thread(workers[0], "worker-"+windex++).start();
			new Thread(workers[1], "worker-"+windex++).start();
			new Thread(workers[2], "worker-"+windex++).start();
		}
		else {
			for (String f : files) {
				parseFile(f);
			}
			long parserStop = System.currentTimeMillis();
			System.out.println("Total lexer+parser time " + (parserStop - parserStart) + "ms.");
		}
	}

	private static void report() {
//		parserStop = System.currentTimeMillis();
//		System.out.println("Lexer total time " + lexerTime + "ms.");
		long time = 0;
		if ( workers!=null ) {
			// compute max as it's overlapped time
			for (Worker w : workers) {
				long wtime = w.parserStop - w.parserStart;
				time = Math.max(time,wtime);
				System.out.println("worker time " + wtime + "ms.");
			}
		}
		System.out.println("Total lexer+parser time " + time + "ms.");

		System.out.println("finished parsing OK");
		//System.out.println(LexerATNSimulator.match_calls+" lexer match calls");
//		System.out.println(ParserATNSimulator.predict_calls +" parser predict calls");
//		System.out.println(ParserATNSimulator.retry_with_context +" retry_with_context after SLL conflict");
//		System.out.println(ParserATNSimulator.retry_with_context_indicates_no_conflict +" retry sees no conflict");
//		System.out.println(ParserATNSimulator.retry_with_context_predicts_same_alt +" retry predicts same alt as resolving conflict");
	}

	public static List<String> getFilenames(File f) throws Exception {
		List<String> files = new ArrayList<String>();
		getFilenames_(f, files);
		return files;
	}

	public static void getFilenames_(File f, List<String> files) throws Exception {
		// If this is a directory, walk each file/dir in that directory
		if (f.isDirectory()) {
			String flist[] = f.list();
			for(int i=0; i < flist.length; i++) {
				getFilenames_(new File(f, flist[i]), files);
			}
		}

		// otherwise, if this is a java file, parse it!
		else if ( ((f.getName().length()>5) &&
			f.getName().substring(f.getName().length()-5).equals(".java")) )
		{
			files.add(f.getAbsolutePath());
		}
	}

	// This method decides what action to take based on the type of
	//   file we are looking at
//	public static void doFile_(File f) throws Exception {
//		// If this is a directory, walk each file/dir in that directory
//		if (f.isDirectory()) {
//			String files[] = f.list();
//			for(int i=0; i < files.length; i++) {
//				doFile_(new File(f, files[i]));
//			}
//		}
//
//		// otherwise, if this is a java file, parse it!
//		else if ( ((f.getName().length()>5) &&
//			f.getName().substring(f.getName().length()-5).equals(".java")) )
//		{
//			System.err.println(f.getAbsolutePath());
//			parseFile(f.getAbsolutePath());
//		}
//	}

	public static void parseFile(String f) {
		try {
			if ( !quiet ) System.err.println(f);
			// Create a scanner that reads from the input stream passed to us
			Lexer lexer = new Java9Lexer(new ANTLRFileStream(f));
			//Lexer lexer = new Java9Lexer(CharStreams.fromString("public class test {}"));

			CommonTokenStream tokens = new CommonTokenStream(lexer);
//			long start = System.currentTimeMillis();
//			tokens.fill(); // load all and check time
//			long stop = System.curre
出口尚哉 No title
Java
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;

public class MyPanel extends JPanel {
	private List<Shape> shapes;

	public MyPanel() {
		super();
		this.shapes = new ArrayList<>();
		MouseAdapter myMcl = new MyMouseClickListener(this);  // change here
		// insert here
		this.addMouseListener(myMcl);
		}

	public void addShape(Shape s) {
		this.shapes.add(s);
		this.repaint();
		}

	public void panelClicked(int x, int y){
		for (Shape s : this.shapes) {
			if (s != null) {
				s.select(x, y);
				}
			}// insert here
		this.repaint();
		}

	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		System.out.println("MyPanel repainting ...");
		for (Shape s : this.shapes) {
			if (s != null) {
				s.draw(g);
				}
			}
		}
	}
anonymous No title
Java
class ExStudent{
	static int Cnt;
	int Stno = 1000; //Student number
	String name;
	int GRD; //Grade
	String DPM; //Department
	int RPT[]; // array of "Report"

	ExStudent(){
		Cnt++;
		Stno += Cnt;
		name = "";
		GRD = 1;
		DPM = "mi";
		RPT = new int[3];
		for (int i = 0; i < 3; i++) RPT[i] = 0;
	}

	ExStudent(String N, int G, String D){
		Cnt++;
		Stno += Cnt;
		name = N;
		GRD = G;
		DPM = D;
		RPT = new int[3];
		for (int i = 0; i < 3; i++) RPT[i] = 0;
	}

	static int getCnt(){ //Get "Cnt"
		return Cnt;
	}
	int getStno(){ //Get "Student Number"
		return Stno;
	}
	void setName(String a){ // Set "Student Name"
		name = a;
	}
	String getName(){ //Get Current "Student Name"
		return name;
	}
	void setGRD(int a){ //Set "Grade"
		GRD = a;
	}
	int getGRD(){ //Get Current "Grade"
		return GRD;
	}
	void setDPM(String a){ //Set "Department"
		DPM = a;
	}
	String getDPM(){ //Get Student's "Department"
		return DPM;
	}
	void setSOR(int no, int score){ //Set "Score of Report"
		RPT[no-1] = score;
	}
	int getSOR(int no){
		return RPT[no-1];
	}
	float getAVG(){ //Get "Average of Scores"
		float tmp = 0;
		for (int i = 0; i < 3; i++){
			tmp += RPT[i];
		}
		return (tmp/3);
	}

	public static void main(String args[]){
		Stdin sin = new Stdin();
		System.out.print("何人の学生がいますか > ");
		int N = sin.geti();
		ExStudent s[] = new ExStudent[N];
		for (int i = 0; i < N; i++){
			System.out.print("\n" + (i+1) + "人目の氏名・学年・学科を教えてください。\n");
			System.out.print("氏名 > ");
			String NAME = sin.gets();
			System.out.print("学年 > ");
			int Grade = sin.geti();
			System.out.print("学科 > ");
			String Department = sin.gets();
			s[i] = new ExStudent(NAME, Grade, Department);
			System.out.println("\n" + "次に" + NAME + "さんのレポートの成績を教えてください。");
			for (int j = 0; j < 3; j++){
				System.out.print(j+1 + "回目 > ");
				int SC = sin.geti();
				s[i].setSOR(j+1, SC);
			}
			
		}

		System.out.println("受講者数:" + getCnt());
		
		for (int i = 0; i < getCnt(); i++){
			System.out.println();
			System.out.println("受講者番号:" + s[i].getStno() + " 氏名:" + s[i].getName() + " " + s[i].getGRD() + "年 " + s[i].getDPM());
			System.out.println("平均" + String.format("%.1f", s[i].getAVG()) + "点 " + "1回目:" + s[i].getSOR(1) + ", 2回目:" + s[i].getSOR(2) + ", 3回目:" + s[i].getSOR(3));
		}
	}
}
anonymous No title
Java
class Student{
	static int Cnt;
	int Stno = 1000; //Student number
	String name;
	int GRD; //Grade
	String DPM; //Department
	int RPT[]; // array of "Report"

	Student(){
		Cnt++;
		Stno += Cnt;
		name = "";
		GRD = 1;
		DPM = "mi";
		RPT = new int[3];
		for (int i = 0; i < 3; i++) RPT[i] = 0;
	}

	Student(String N, int G, String D){
		Cnt++;
		Stno += Cnt;
		name = N;
		GRD = G;
		DPM = D;
		RPT = new int[3];
		for (int i = 0; i < 3; i++) RPT[i] = 0;
	}

	static int getCnt(){ //Get "Cnt"
		return Cnt;
	}
	int getStno(){ //Get "Student Number"
		return Stno;
	}
	void setName(String a){ // Set "Student Name"
		name = a;
	}
	String getName(){ //Get Current "Student Name"
		return name;
	}
	void setGRD(int a){ //Set "Grade"
		GRD = a;
	}
	int getGRD(){ //Get Current "Grade"
		return GRD;
	}
	void setDPM(String a){ //Set "Department"
		DPM = a;
	}
	String getDPM(){ //Get Student's "Department"
		return DPM;
	}
	void setSOR(int no, int score){ //Set "Score of Report"
		RPT[no-1] = score;
	}
	int getSOR(int no){
		return RPT[no-1];
	}
	float getAVG(){ //Get "Average of Scores"
		float tmp = 0;
		for (int i = 0; i < 3; i++){
			tmp += RPT[i];
		}
		return (tmp/3);
	}

	public static void main(String args[]){
		Stdin sin = new Stdin();
		Student s[] = new Student[5];
		s[0] = new Student("高専太郎", 1, "ms");
		s[1] = new Student("沖縄次郎", 3, "ic");
		s[2] = new Student("高専花子", 4, "mi");
		s[3] = new Student("名護三郎", 1, "br");
		s[4] = new Student("高専哲郎", 1, "mi");

		//about s0
		s[0].setSOR(1, 60);
		s[0].setSOR(2, 70);
		s[0].setSOR(3, 80);

		//about s1
		s[1].setSOR(1, 0);
		s[1].setSOR(2, 70);
		s[1].setSOR(3, 60);

		//about s2
		s[2].setSOR(1, 80);
		s[2].setSOR(2, 0);
		s[2].setSOR(3, 75);

		//about s3
		s[3].setSOR(1, 70);
		s[3].setSOR(2, 50);
		s[3].setSOR(3, 90);

		//about s4
		s[4].setSOR(1, 90);
		s[4].setSOR(2, 85);
		s[4].setSOR(3, 80);

		System.out.println("受講者数:" + getCnt());
		
		for (int i = 0; i < getCnt(); i++){
			System.out.println();
			System.out.println("受講者番号:" + s[i].getStno() + " 氏名:" + s[i].getName() + " " + s[i].getGRD() + "年 " + s[i].getDPM());
			System.out.println("平均" + String.format("%.1f", s[i].getAVG()) + "点 " + "1回目:" + s[i].getSOR(1) + ", 2回目:" + s[i].getSOR(2) + ", 3回目:" + s[i].getSOR(3));
		}
	}
}
anonymous No title
Java
class random1{
	public static void main(String args[]){
		double a = Math.random();
		System.out.println(a);
		int RDM = (int)(Math.random() * 100);
		System.out.println(RDM);
	}
}
anonymous No title
Java
package datashori;

import java.io.IOException;

public class shimon10 {

	public static void main(String[] args) {


	try {

		ProcessBuilder p = new ProcessBuilder("C:\\workspace\\datashori\\libsvm-3.24\\libsvm-3.24svm-train.c","-v3","C:\\workspace\\datashori\\rakuten1.file");
		p. redirectErrorStream(true);
		p.start();

         }catch(IOException e) {

        	 e.printStackTrace();

         }
}
}
anonymous No title
Java
package datashori;

import java.io.File;
import java.io.IOException;

public class shimon10 {

	public static void main(String[] args) {


	try {

		ProcessBuilder p = new ProcessBuilder("C:\\workspace\\datashori\\libsvm-3.24\\libsvm-3.24svm-train.c","-v3","cd");
		p. redirectErrorStream(true);
		p.start();

         }catch(IOException e) {

        	 e.printStackTrace();

         }
}
}
anonymous No title
Java
【レフェリークラス】
class Practice2_02_1_referee{
	
	//------フィールド-------
	private String name ;
	
	//------コンストラクタ------
	Practice2_02_1_referee( String nm ){
		this.name = nm ;
	}
	
	//------メソッド-------
	
	//declareHandStatusメソッド
	public void declareHandStatus( Practice2_02_1_player player1,Practice2_02_1_player player2 ){
		System.out.println( "審判" + this.name + ":「" + player1.getName() + "さんの手は" + player1.getHandStatus() + "でした!!」" );
		System.out.println( "審判" + this.name + ":「" + player2.getName() + "さんの手は" + player2.getHandStatus() + "でした!!」" );
	}
	
	//judgeGameメソッド
	public void judgeGame( Practice2_02_1_player player1,Practice2_02_1_player player2 ){
		
		if(player1.getHandStatus().equals(player2.getHandStatus())){
			
			System.out.println( "審判" + this.name + ":「あいこ!勝負つかず!!!」" ) ;
			
		}else if(((player1.getHandStatus().equals("グー"))&&(player2.getHandStatus().equals("チョキ")))||((player1.getHandStatus().equals("パー"))&&(player2.getHandStatus().equals("グー")))||((player1.getHandStatus().equals("チョキ"))&&(player2.getHandStatus().equals("パー")))){		
			
			System.out.println( "審判" + this.name + ":「" + player1.getName() + "さんの勝ち」" ) ;
			
		}else if(((player2.getHandStatus().equals("グー"))&&(player1.getHandStatus().equals("チョキ")))||((player2.getHandStatus().equals("パー"))&&(player1.getHandStatus().equals("グー")))||((player2.getHandStatus().equals("チョキ"))&&(player1.getHandStatus().equals("パー")))){
			
			System.out.println( "審判" + this.name + ":「" + player2.getName() + "さんの勝ち」" ) ;
			
		}
	}
	
	//-----getter/setter-------
	public String getName(){
		return this.name;
	}
	public void setName(){
		this.name = name ;
	}
	
}


anonymous No title
Java
【プレイヤークラス】
import java.util.Random;

class Practice2_02_1_player{
	
	//-------フィールド------
	private String name ;
	private String handStatus ;
	
	//-------コンストラクタ--------
	Practice2_02_1_player( String nm ){
		this.name = nm ;
	}
	
	//-------メソッド---------
	public void makeHandStatus(){
		String[] makeHands = { "グー","チョキ","パー" };
		
		Random rnd = new Random();
		this.handStatus = makeHands[rnd.nextInt(3)] ;
	}
	
	//-------getter/setter--------
	
	public String getName(){
		return this.name ;
	}
	public void setName(){
		this.name = name ;
	}
	
	public String getHandStatus(){
		return this.handStatus ;
	}
	public void setHandStatus(){
		this.handStatus = handStatus ;
	}
	
}
anonymous No title
Java
【メインクラス】
class Practice2_02_1_janken{
	public static void main(String[] args){
		
		//------シナリオ①---------
		String player1_nm = args[0] ;
		String player2_nm = args[1] ;
		String judgement_nm = args[2] ;
		
		//------シナリオ②---------
		Practice2_02_1_player player1 = new Practice2_02_1_player( player1_nm );
		Practice2_02_1_player player2 = new Practice2_02_1_player( player2_nm );
		Practice2_02_1_referee referee = new Practice2_02_1_referee( judgement_nm );
		
		//------シナリオ③---------
		System.out.println( "審判" + referee.getName() + ":「ジャンケン…ポン!!!!!」" ) ;
		player1.makeHandStatus();
		player2.makeHandStatus();
		referee.declareHandStatus( player1,player2 );
		
		//------シナリオ④---------
		System.out.println( "審判" + referee.getName() + ":「結果は……」" );
		referee.judgeGame( player1,player2 );
		
	}
}
Don't you submit code?
Submit