ログインしてさらにmixiを楽しもう

コメントを投稿して情報交換!
更新通知を受け取って、最新情報をゲット!

制御情報工学科_H20年度卒業生コミュのじゃヴぁ

  • mixiチェック
  • このエントリーをはてなブックマークに追加

コメント(9)

メインクラス

package bus;
import java.io.*;
/**
*
* @author
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}




/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int i;
String[]nos={"東京行きのバス","京都行きのバス","大阪行きのバス"};
bus2[]bu=new bus2[nos.length];
for(i=0;i<bu.length;i++){
bu[i]=new bus2(nos[i]);
}
System.out.println("東京行きのバスなら0を京都行きのバスなら1を大阪行きのバスなら2を入力してください");
String strs=br.readLine();
int s=Integer.parseInt(strs);
//int s= (int)(Math.random()*3);//バス決め
System.out.println("予約人数を入力してください");
String strn=br.readLine();
int n=Integer.parseInt(strn);

//int n= (int)(Math.r0andom()*17);//人数
for(i=1;i<=n;i++){
System.out.println("席を指定するなら1を、そうでないなら0を入力してください");
String strd=br.readLine();
int d=Integer.parseInt(strd);
//int d= (int)(Math.random()*2);//指定かそうでないか
System.out.println("男性なら1を女性なら2を入力してください");
String strh=br.readLine();
int h=Integer.parseInt(strh);
//int h= (int)(Math.random()*2)+1;//性別
if(d==0){bu[s].kime(h);}
if(d==1){
while(true){
System.out.println("横0から3行のどこがいいですか");
String stry=br.readLine();
int y=Integer.parseInt(stry);
//int y= (int)(Math.random()*4);
System.out.println("縦0から3列のどこがいいですか");
String strt=br.readLine();
int t=Integer.parseInt(strt);
//int t= (int)(Math.random()*4);
if((bu[s].sekika(y,t)!=bu[s].m)&&(bu[s].sekika(y,t)!=bu[s].f)){
bu[s].kime(h,y,t);
break;

}
System.out.println("そこはもう予約が入ってます");

}
}
}
bu[s].show();

}

}
サブクラス

public class bus2 {
String no;
int t=0;int y=0;
int k=0;int m=1;int f=2;
int seki[][]=new int[4][4];
/** Creates a new instance of bus2 */
public bus2() {
while(y<4){
while(t<4){
seki[y][t]=k;
t++;
}
y++;
}

}
public bus2(String x){
no=x;
while(y<4){
while(t<4){
seki[y][t]=k;
t++;
}
y++;
}
t=0;y=0;

}
//男性か女性の一人予約(どうでもいい場合)
public void kime(int x){
t=0;y=0;
while(seki[y][t]!=0){
t++;
if(t==4){
t=0;
y++;
}



}

//if((seki[0][t]==x)||(seki[][]==0)){}
seki[y][t]=x;

}
//一人予約(指定)
public void kime(int x, int a, int b){
seki[a][b]=x;
}


public void show(){
System.out.println(no+"は");
for(int i=0;i<seki.length;i++){
for(int j=0;j<seki[i].length;j++){
if(seki[i][j]==0){System.out.println(i+"-"+j+"は空席");}
else if(seki[i][j]==m){System.out.println(i+"-"+j+"は男性");}
else if(seki[i][j]==f){System.out.println(i+"-"+j+"は女性");}
}
}

}
public int sekika(int a,int b){return seki[a][b];}



}
ちなみにこれらはまだ完全じゃない。
隣に異性が座ってしまうプログラムです。
とりあえず、できなかったときの保険みたいなもの。
できたらまた書き込んどきます。
public class bus2 {
String no;
int t=0;int y=0;
int k=0;int m=1;int f=2;
int seki[][]=new int[4][4];
/** Creates a new instance of bus2 */
public bus2() {
while(y<4){
while(t<4){
seki[y][t]=k;
t++;
}
y++;
}

}
public bus2(String x){
no=x;
while(y<4){
while(t<4){
seki[y][t]=k;
t++;
}
y++;
}
t=0;y=0;

}
//男性か女性の一人予約(どうでもいい場合)
public void kime(int x){
t=0;y=0;
while(seki[y][t]!=0){
t++;
if(t==4){
t=0;
y++;
}



}
while((y>=1)&&(y<=3)){
if((seki[y-1][t]==x)||(seki[y-1][t]==0)){break;}
else{
t++;
if(t==4){
t=0;
y++;
}
}
}
//if((seki[y-1][t]==x)){}
seki[y][t]=x;

}
//一人予約(指定)
public void kime(int x, int a, int b){
seki[a][b]=x;
}


public void show(){
System.out.println(no+"は");
for(int i=0;i<seki.length;i++){
for(int j=0;j<seki[i].length;j++){
if(seki[i][j]==0){System.out.println(i+"-"+j+"は空席");}
else if(seki[i][j]==m){System.out.println(i+"-"+j+"は男性");}
else if(seki[i][j]==f){System.out.println(i+"-"+j+"は女性");}
}
}

}
public int sekika(int a,int b){return seki[a][b];}



}



さっきのサブクラスの改良型。
だけどこれも、都合のよいプログラなので、自分であとは改良して
いや、確か授業までなら大丈夫なはず
メイン

package 練習;
import java.io.*;
/**
*
* @author
*/

public class Main {

/** Creates a new instance of Main */
public Main() {
}



/**
* @param args the command line arguments
*/

public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
int i;
String[]nos={"ポカリスエット","十六茶","コーラ"};
NewClass[] ma=new NewClass[nos.length];
for(i=0;i<ma.length;i++){
ma[i]=new NewClass(nos[i]);
}
for(i=0;i<ma.length;i++){
int t= 3;//(int)(Math.random()*100);
ma[i].tuika(t);
}
while(true){
System.out.println("ポカリスエットなら0を十六茶なら1をコーラなら2を押してください");
String strs=br.readLine();
int s=Integer.parseInt(strs);
//int s= (int)(Math.random()*3);
System.out.println("何個買いますか?");
String stru=br.readLine();
int u=Integer.parseInt(stru);
//int u= (int)(Math.random()*50);
ma[s].uri(u);
System.out.println("まだ買うなら1を買わないなら0を押してください");
String strw=br.readLine();
int w=Integer.parseInt(strw);
if(w==0){break;}
}
for(i=0;i<ma.length;i++){
ma[i].show();
}
int k=ma[0].uriage()+ma[1].uriage()+ma[2].uriage();
System.out.println("総売上は"+k+"円です");
}

}
サブ

public class NewClass {
String no;
int mouke;
int nokori;
/** Creates a new instance of NewClass */
public NewClass() {
mouke=0;
nokori=0;
}
public NewClass(String x){
no=x;
mouke=0;
nokori=0;
}
public void tuika(int x){nokori=nokori+x;}

public void uri(int x){
if(nokori>=x){nokori=nokori-x;
mouke=mouke+150*x;
}
else{
mouke=mouke+150*(nokori);
System.out.println(nokori+"本までしか買えませんでした。もう売り切れです");
nokori=0;
}
}
public void show(){System.out.println(no+"の儲けは"+mouke+"円、残りは"+nokori+"本");}

public int uriage(){return mouke;}
}

釣りは考えねぇ

ログインすると、みんなのコメントがもっと見れるよ

mixiユーザー
ログインしてコメントしよう!

制御情報工学科_H20年度卒業生 更新情報

制御情報工学科_H20年度卒業生のメンバーはこんなコミュニティにも参加しています

星印の数は、共通して参加しているメンバーが多いほど増えます。