---
# System prepended metadata

title: "\U0001F308專三JAVA"
tags: [school]

---

###### tags: `school`
# 🌈專三JAVA
## 專三JAVA 
### Ch3 變數與運算式(實作題)

:::warning
 **W2 印出學號**
https://replit.com/@LIANGcode/W2-Yin-Chu-Xue-Hao#Main.java

 **W5 001(運算式執行)**
https://replit.com/@LIANGcode/W5-001Yun-Suan-Shi-Zhi-Xing#Main.java

**W5 002(運算式執行)**
https://replit.com/@LIANGcode/W5-002Yun-Suan-Shi-Zhi-Xing#Main.java

**W5 003(運算式執行)**
https://replit.com/@LIANGcode/W5-003Yun-Suan-Shi-Zhi-Xing
**W5 004(公式執行)**
https://replit.com/@LIANGcode/W5-004Gong-Shi-Zhi-Xing#Main.java
**W5 005(改變其中一個運算子，達到題目要求)**
https://replit.com/@LIANGcode/W5-005Gai-Bian-Qi-Zhong-Yi-Ge-Yun-Suan-Zi-Da-Dao-Ti-Mu-Yao-Qiu#Main.java
**W5 006(公式鍵盤輸入)**
https://replit.com/@LIANGcode/W5-006Gong-Shi-Jian-Pan-Shu-Ru#Main.java
 **W5 007(改變程式，達到題目要求)**
https://replit.com/@LIANGcode/W5-007Gai-Bian-Cheng-Shi-Da-Dao-Ti-Mu-Yao-Qiu#Main.java
**W5 008(改變程式，達到題目要求)**
https://replit.com/@LIANGcode/W5-008Gai-Bian-Cheng-Shi-Da-Dao-Ti-Mu-Yao-Qiu#Main.java
**W5 009(改變程式，達到題目要求)**
https://replit.com/@LIANGcode/W5-009Gai-Bian-Cheng-Shi-Da-Dao-Ti-Mu-Yao-Qiu#Main.java
**W5 010(改變程式，達到題目要求)**
https://replit.com/@LIANGcode/W5-010Gai-Bian-Cheng-Shi-Da-Dao-Ti-Mu-Yao-Qiu#Main.java
:::

### Ch4 流程控制(實作題)

:::warning
**Ch4 - 001(三數最大值)**
https://replit.com/@LIANGcode/Ch4-001San-Shu-Zui-Da-Zhi#Main.java
**Ch4 - 002(2~100中所有質數，每5個換行顯示)**
https://replit.com/@LIANGcode/Ch4-0022100Zhong-Suo-You-Zhi-Shu-Mei-5Ge-Huan-Xing-Xian-Shi#Main.java
**Ch4 - 003(偶數乘法表)**
https://replit.com/@LIANGcode/Ch4-003Ou-Shu-Cheng-Fa-Biao#Main.java
**Ch4 - 004(數1~n 1~n乘方)**
https://replit.com/@LIANGcode/Ch4-004Shu-1n-1nCheng-Fang#Main.java
**Ch4 - 005(單一迴圈，乘法表)**
https://replit.com/@LIANGcode/Ch4-005Dan-Yi-Hui-Quan-Cheng-Fa-Biao#Main.java
**Ch4 - 006(計程車費)**
https://replit.com/@LIANGcode/Ch4-006Ji-Cheng-Che-Fei#Main.java
**Ch4 - 007(閏年檢查)**
https://replit.com/@LIANGcode/Ch4-007Run-Nian-Jian-Cha#Main.java
**Ch4 - 008(m=n!)**
https://replit.com/@LIANGcode/Ch4-008mn#Main.java
**Ch4 - 009(大小寫字母轉換)**
https://replit.com/@LIANGcode/Ch4-009Da-Xiao-Xie-Zi-Mu-Zhuan-Huan#Main.java
**Ch4 - 010(是否為一個三角形)**
https://replit.com/@LIANGcode/Ch4-010Shi-Fou-Wei-Yi-Ge-San-Jiao-Xing#Main.java
**Ch4 - 011(是否為直角三角形)**
https://replit.com/@LIANGcode/Ch4-011Shi-Fou-Wei-Zhi-Jiao-San-Jiao-Xing#Main.java
**Ch4 - 012(x的y次方)**
https://replit.com/@LIANGcode/Ch4-012xDe-yCi-Fang#Main.java
**Ch4 - 013(1!+2!+...+m!)(0<m<10)**
https://replit.com/@LIANGcode/Ch4-01312m0lessmless10#Main.java
**Ch4 - 014(吐出最少硬幣)**
https://replit.com/@LIANGcode/Ch4-014Tu-Chu-Zui-Shao-Ying-Bi#Main.java
**10/21(1~n 的m倍數總和)**
https://replit.com/@LIANGcode/10211n-De-mBei-Shu-Zong-He#Main.java
:::


### Ch5 陣列(實作題)
:::warning
**Ch5-001輸入查詢對象，輸出電話號**
https://replit.com/@LIANGcode/Ch5-001Shu-Ru-Cha-Xun-Dui-Xiang-Shu-Chu-Dian-Hua-Hao#Main.java
**Ch5-002矩陣轉置**
https://replit.com/@LIANGcode/Ch5-002Ju-Zhen-Zhuan-Zhi#Main.java
**Ch5-003矩陣相乘**
https://replit.com/@LIANGcode/Ch5-003Ju-Zhen-Xiang-Cheng#Main.java
**Ch5-004存放學生成績，畫出分布圖**
https://replit.com/@LIANGcode/Ch5-004Cun-Fang-Xue-Sheng-Cheng-Ji-Hua-Chu-Fen-Bu-Tu#Main.java
**w7 印出直角三角形**
https://replit.com/@LIANGcode/w7-Yin-Chu-Zhi-Jiao-San-Jiao-Xing#Main.java
**Ch5-005楊輝三角形**
https://replit.com/@LIANGcode/Ch5-005Yang-Hui-San-Jiao-Xing#Main.java

:::
### Ch6函式(上課習題)
:::warning
**3.跟電腦猜拳**
https://replit.com/@LIANGcode/3Gen-Dian-Nao-Cai-Quan#Main.java
**4. 擲骰子50次，請列出 1~6 點總共出現的次數**
https://replit.com/@LIANGcode/4-Zhi-Tou-Zi-50Ci-Qing-Lie-Chu-16-Dian-Zong-Gong-Chu-Xian-De-Ci-Shu#Main.java
**Ch6-001(函式 : 字串複製n次)**
https://replit.com/@LIANGcode/Ch6-001Han-Shi-Zi-Chuan-Fu-Zhi-nCi#Main.java
**Ch6-002(函式 : 商數餘數)**
https://replit.com/@LIANGcode/Ch6-002Han-Shi-Shang-Shu-Yu-Shu#Main.java
**Ch6-003(函式 : 100個亂數平均)**
https://replit.com/@LIANGcode/Ch6-003Han-Shi-100Ge-Luan-Shu-Ping-Jun#Main.java
**Ch6-004(ab乘法表)**
https://replit.com/@LIANGcode/Ch6-004abCheng-Fa-Biao#Main.java
**Ch6(11/25二維陣列之最大值並回傳)**
https://replit.com/@LIANGcode/Ch61125Er-Wei-Zhen-Lie-Zhi-Zui-Da-Zhi-Bing-Hui-Chuan#Main.java
**Ch6(11/25問答7)**
https://replit.com/@LIANGcode/Ch61125Wen-Da-7#Main.java
**Ch6(11/25問答8)**
https://replit.com/@LIANGcode/Ch61125Wen-Da-8#Main.java
**Ch6(11/25遞迴函式計算出x的y次方)**
https://replit.com/@LIANGcode/Ch61125Di-Hui-Han-Shi-Ji-Suan-Chu-xDe-yCi-Fang#Main.java
**Ch6-011(函數 : 是否為質數)**
https://replit.com/@LIANGcode/Ch6-011Han-Shu-Shi-Fou-Wei-Zhi-Shu#Main.java
**Ch6-012(4j3)**
https://replit.com/@LIANGcode/Ch6-0124j3#Main.java
**Ch6-013(檢查到2~n開根號即可)**
https://replit.com/@LIANGcode/Ch6-013Jian-Cha-Dao-2nKai-Gen-Hao-Ji-Ke#Main.java
:::

### Ch7(物件導向程式設計)
:::warning
**Ch7 - 001(三角形類別)**
https://replit.com/@LIANGcode/Ch7-001San-Jiao-Xing-Lei-Bie#Main.java
**u7上課作業(12/2(4))**
https://replit.com/@LIANGcode/u7Shang-Ke-Zuo-Ye-1224#Main.java
**u7上課作業(12/2(5))**
https://replit.com/@LIANGcode/u7Shang-Ke-Zuo-Ye-1225#Main.java
**Ch7 -002**
https://replit.com/@LIANGcode/Ch7-002#Main.java
**Ch7 - 003(人事資料類別)**
https://replit.com/@LIANGcode/Ch7-003Ren-Shi-Zi-Liao-Lei-Bie#Main.java
**Ch7 - 004(飛行器類別)**
https://replit.com/@LIANGcode/Ch7-004Fei-Xing-Qi-Lei-Bie#Main.java
:::
### Ch8(繼承)
:::warning
**Ch8-001(印出小於x的質數，定義CA的子類別CB)**
https://replit.com/@LIANGcode/Ch8-001Yin-Chu-Xiao-Yu-xDe-Zhi-Shu-Ding-Yi-CADe-Zi-Lei-Bie-CB#Main.java
**Ch8-002(印出x的三次方、階層，定義CA的子類別CB)**
https://replit.com/@LIANGcode/Ch8-002Yin-Chu-xDe-San-Ci-Fang-Jie-Ceng-Ding-Yi-CADe-Zi-Lei-Bie-CB#Main.java
**Ch8-003(抽象類別，印出多邊形內角和)**
https://replit.com/@LIANGcode/Ch8-003Chou-Xiang-Lei-Bie-Yin-Chu-Duo-Bian-Xing-Nei-Jiao-He#Main.java
**ch8-004(接第七章 : 加上海龍公式計算三角形面積)**
https://replit.com/@LIANGcode/ch8-004Jie-Di-Qi-Zhang-Jia-Shang-Hai-Long-Gong-Shi-Ji-Suan-San-Jiao-Xing-Mian-Ji#Main.java
:::
### Ch9(介面)
:::warning
**Ch9-001**
https://replit.com/@LIANGcode/Ch9-001#Main.java
**Ch9-002**
https://replit.com/@LIANGcode/Ch9-002#Main.java
**Ch9-003**
https://replit.com/@LIANGcode/Ch9-003#Main.java
**ch9-004**
https://replit.com/@LIANGcode/ch9-004#Main.java
**ch9-005**
https://replit.com/@LIANGcode/ch9-005#Main.java
:::
### 期中考
:::info
**s1110834007Ans1 (數學公式)**
```JAVA=
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
   double n;
			System.out.print("輸入數字 : ");
			Scanner input=new Scanner(System.in);
			n=input.nextInt();
			
			double ans=0;
			double total=0;
			for(int j=1;j<=n*n;j++)
			{
			for(int i=1;i<=n*n;i++)
			{
				ans=(n-2)/n;
				total=total+ans;
				n=n-2;	
			}  
			}
			float end=(float)total;
			System.out.print("total="+end);
  }
}
```
**s1110834007Ans2(工作時數)**
```JAVA=
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
   	
		int x=0;
		int money=0;
		int add=0;
		int all=0;
		int notime=0;
	while(true)
	{
		System.out.print("請輸入該月工作時數=>");
		Scanner input=new Scanner(System.in);
		x=input.nextInt();
		if(x>205)
		{
			money=160*105;
			double temp= 105*1.5*(205-160);
			int tt=(int)temp;
			
			add=tt;
			all=tt+money;
			notime=x-205;
		}
		if(x>=161&&x<=205)
		{
			money=160*105;
			double temp= 105*1.5*(x-160);
			int tt=(int)temp;
			add=tt;
			all=tt+money;
			notime=0;
		}
		if(x<=160)
		{
			money=x*105;
			add=0;
			all=money;
			notime=0;
		}
		
		System.out.println("本月基本薪資如下 : ");
		System.out.println("基本薪資= "+money);
		System.out.println("加班費= "+add);
		System.out.println("總共薪資= "+all);
		System.out.println("不計費時間= "+notime+"小時");
		}
  }
}
```
**s1110834007Ans3(等邊三角形)**
```JAVA=
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
   	System.out.print("請輸入等邊三角形的高度=>");
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		
		for(int i=1;i<n+2;i++)
		{
			for(int j=0;j<=n+2-i;j++)
			{
				System.out.print(" ");
			}
			
			for(int k=1;k<=i-1;k++)
			{
				System.out.print(" ");
				System.out.print("*");
			}
			System.out.print("\n");
		}
  }
}
```
**s1110834007Ans4(心算小測驗)**
```JAVA=
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
   	System.out.println("**** 心算小測驗-加法 ******");
		Scanner input=new Scanner(System.in);
		int temp=0,temp2=0;
		int ans=0;
		int T=0,F=0;
		int again=1;
		while(again==1)
		{	
		for(int i=1;i<=5;i++)
		{
		temp=(int)((Math.random()*10)+0);
		temp2=(int)((Math.random()*10)+0);
		System.out.print("第"+i+"題 : "+temp+"+"+temp2+"=");
		int n=input.nextInt();
		
		if(n==temp+temp2)
		{
			System.out.println("好棒! 答對了!");
			T++;
		}
		else
		{
			System.out.println("加油! 答錯了!");
			F++;
		}
		}
		System.out.println("答對題數="+T+","+"答錯題數="+F);
		T=0;F=0;
		System.out.print("是否重新練習一次?(1:重新開始 2:遊戲結束)");
		again=input.nextInt();
		if(again==2)
		{
			System.out.println("Game Over");
		}
		}	
  }
}
```
**s1110834007Ans5(隨機陣列數值相加)**
```JAVA=
class Main {
  public static void main(String[] args) {
   int m1[][]=new int[3][3];
     int m2[][]=new int[3][3];
     int m3[][]=new int[3][3];
	
     System.out.print("我是陣列Y\n");
     for(int i=0;i<3;i++)
     {
    	 for(int j=0;j<3;j++)
         {
    		 m1[i][j]=(int)((Math.random()*31)+0);
    		 System.out.print(m1[i][j]+"\t");
         }
    	 System.out.print("\n");
     }
    
     System.out.print("我是陣列X\n");
     for(int i=0;i<3;i++)
     {
    	 for(int j=0;j<3;j++)
         {
    		 m2[i][j]=(int)((Math.random()*31)+0);
    		 System.out.print(m2[i][j]+"\t");
         }
    	 System.out.print("\n");
     }
     System.out.print("我是陣列Z=X+Y\n");
     int total=0;
     for(int i=0;i<3;i++)
     {
    	 for(int j=0;j<3;j++)
         {
    		 m3[i][j]=m2[i][j]+m1[i][j];
    		 System.out.print(m3[i][j]+"\t");
    		 total=total+m3[i][j];
         }
    	 System.out.print("\n");
     }
     System.out.print("我是總和 : "+total);
	
  }
}
```
**s1110834007Ans6(輸入一個三位整數，檢視它是否為迴文)**
```JAVA=
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
   while(true)
		{
		System.out.print("輸入一個三位整數，檢視它是否為迴文 : ");
		Scanner input=new Scanner(System.in);
		String n=input.next();
		
		if(n.length()!=3)
		{
			 System.out.println("請輸入三位數整數!");
			 continue;
		}
		 if(n.charAt(0)==n.charAt(2))
		 {
			 System.out.println(n+ " is a palindrome number.");
		 }
		 else		 
		 {
			 System.out.println(n+" is not a palindrome number.");
		 }
		}	
  }
}
```
:::
### 期末考
:::info
**s1110834007Ans1(類別啦~)**
```JAVA=
public class Main {
    public static void main(String[] ager) {
    	 int[] temp;
       
    	CFlyMachine objArr[]=new CFlyMachine[10];
    	  for (int i = 0; i < objArr.length; i++) {
              temp = makeThreeNum();
              objArr[i] = new CFlyMachine(temp[0], temp[1], temp[2]);
          }
    	  
    	  CFlyMachine a=new CFlyMachine();
          a.printc();
          
          System.out.println("速度\t載重量\t類型\t");
          for (int i = 0; i < objArr.length; i++) {
              objArr[i].printData();
          }
    }
    static int[]makeThreeNum()  //產生亂數的函式
    {
  	  int arr[]=new int [3];
  	  arr[0]=(int)((Math.random()*45001)+5000);
  	  arr[1]=(int)((Math.random()*30001)+10000);
  	  arr[2]=(int)((Math.random()*4));	  
      return arr;
    }	
}
class CFlyMachine //飛行器類別
{
	public int speed; //速度
	public int carryCapacity; //載重量
	public int machineType; //類型
	public static int  counter=0;  //類型為2的分行器數量
 
	public CFlyMachine(){
		speed=0;
		carryCapacity=0;
		machineType=0;
	  // counter=0;  
	}
	public CFlyMachine(int speed,int carryCapacity,int machineType){
		this.speed=speed;
		this.carryCapacity=carryCapacity;
		this.machineType=machineType;
	    this.counter=counter;
    	if(machineType==2)
		{
			counter+=1;
		}
    
	}
	public void printData(){
		System.out.println(speed+"\t"+carryCapacity+"\t"+machineType);
		if(machineType==2)
		{
			print();
		}
	}
	private void print()
	{
		System.out.println("**多一架***");
	}
	public void printc()
	{
	  System.out.println("類型為2的飛行器有"+counter+"架");  
	} 
}

```
**s1110834007Ans2(關於圓的類別)**
```JAVA=
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CSphere call=new CSphere();
		call.setLocation();
		call.setRadius();
		call.showCenter();
		System.out.println("surface area="+call.surfaceArea());
		System.out.println("volume="+call.volume());
	}

}
class CSphere
{
	private int x;  //x座標
	private int y;  //y座標
	private int z;  //z座標
	private int radius;    //圓心半徑
	 
	public void setLocation()  //圓心位置
	{
		x=3;
		y=4;
		z=5;
	}	
	public void setRadius()  //設定半徑
	{
		radius=1;
	}
	public double surfaceArea()  //傳回表面積
	{
		double PI=3.14;
		return 4*PI*radius*radius; 
	}
	public double volume()  //傳回體積
	{
		double PI=3.14;
	double temp=(double)4/3;
		return temp*PI*radius*radius*radius; 
	}
	public void showCenter()  //顯示圓心座標
	{
		System.out.println("x="+x+", y="+y+" ,z="+z);
	}
	
}


```
**s1110834007Ans3(解二元一次方程式)**
```JAVA=
import java.lang.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int arr[]=new int[3];
		int temp[]=new int[2];
		int t=0;
		while(true)
		{
		  arr=netxInt();
		  int c=0;
		  for(int i=100;i>=-100;i--)
		  {
			  if(arr[0]*Math.pow(i, 2)+arr[1]*i+arr[2]==0)
		  	 {
				 temp[t]=i;
				 t++;
		 		 c++;
			 }
		  }
		  if(c==2)
		  {
		    if(arr[0]==1&&arr[1]==1)
		    	System.out.println("x^2+"+"x+"+arr[2]+"=0 的兩根，分別為"+temp[0]+","+temp[1]);
		    if(arr[0]==1&&arr[1]!=1)
		    	System.out.println("x^2+"+arr[1]+"x+"+arr[2]+"=0 的兩根，分別為"+temp[0]+","+temp[1]);
		    if(arr[0]!=1&&arr[1]!=1)
		    	System.out.println(arr[0]+"x^2+"+"x+"+arr[2]+"=0 的兩根，分別為"+temp[0]+","+temp[1]);
		  }
		  else if(c==0)
		  {
			  if(arr[0]==1&&arr[1]==1)
			    	System.out.println("x^2+"+"x+"+arr[2]+"=0 沒有實根");
			    if(arr[0]==1&&arr[1]!=1)
			    	System.out.println("x^2+"+arr[1]+"x+"+arr[2]+"=0 沒有實根");
			    if(arr[0]!=1&&arr[1]!=1)
			    	System.out.println(arr[0]+"x^2+"+"x+"+arr[2]+"=0 沒有實根");
		  }
		}
	}
	public static int[] netxInt()  //讀入以空白間隔的數字
	{
		int a=0,b=0,c=0;
		System.out.print("請輸入ax^2+bx+c=0 的係數a、b及c(以空白隔開) : ");
		Scanner input =new Scanner(System.in);
		a=input.nextInt();
		b=input.nextInt();
		c=input.nextInt();
		int temp[]=new int[3];
		temp[0]=a;
		temp[1]=b;
		temp[2]=c;
		return  temp;
	}
}

```
**s1110834007Ans4(遞迴)**
```JAVA=
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
       System.out.print("1*2+2*3+3*4+...+(5-1)*5="+rsum(5));
       
	}
	
	public static int rsum(int n)
	{
		int all=0;
		int ans=1;
		int temp;
		if(n>1)
		{
			all=0;
			ans=n;
			n--;
			temp=n*ans;
			rsum(n);		
			return temp+temp;
		}
		return all;
	}

}

```
**s1110834007Ans5(看圖)**

```JAVA=
class Main {
  public static void main(String[] args) {
  
  }
}

interface IAddress
{
	public abstract String  getAddress();
}

 class Person
{
	private int id;
	private String name;
	
	public int getID()
	{
		return id;
	}
	public String getName()
	{
		return name;
	}
}

 class Member extends Person implements IAddress
{
	public int memberNo;
	private String address;
	public int age;
	
	Member call=new Member();
	public void memberinfo()
	{
		System.out.print("memberNo : "+ memberNo+" age : "+age+"Address"+call.getAddress());
	}
  public String  getAddress()
	{
		return address;
	}
}

```
:::

