Github 備份:LINK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ JAVA6 - 607_1 */ | |
//建立NB的類別 | |
class NB{ | |
int cost; | |
NB(int i){ | |
if(i==1) | |
cost=10000; | |
else | |
cost=8500; | |
} | |
int getCost(){ | |
return cost; | |
} | |
} | |
public class JPA06_1 { | |
public static void main(String args[]){ | |
NB e1 = new NB(1); | |
System.out.println("一台17'筆記型電腦成本:"+e1.getCost()); | |
NB e2 = new NB(2); | |
System.out.println("一台14'筆記型電腦成本:"+e2.getCost()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ JAVA6 - 607_2 */ | |
class NB{ | |
int cost; | |
NB(int i){ | |
if(i==1) | |
cost=5000; | |
else | |
cost=8500;} | |
int getCost(){ | |
return cost; | |
} | |
} | |
//建立CPU類別 | |
class CPU{ | |
int cost; | |
CPU(String s){ | |
if(s.equals("basic")) | |
cost = 1000; | |
else | |
cost = 2000; | |
} | |
int getCost(){ | |
return cost; | |
} | |
} | |
abstract class CNB{ | |
NB b; | |
CPU c; | |
//建構子初始化,傳入NB等級和CPU等級 | |
CNB(int i,String s){ | |
b=new NB(i); | |
c=new CPU(s); | |
} | |
//建立成本方法 | |
abstract double cost(); | |
//建立價錢方法 | |
double price(){ | |
return cost()*1.5; | |
} | |
} | |
//繼承CNB | |
class BasicNB extends CNB{ | |
BasicNB(int i ,String s){ | |
super(i,s); | |
} | |
double cost(){ | |
return b.getCost()+c.getCost()+1000; | |
} | |
} | |
//繼承CNB | |
class LuxNB extends CNB{ | |
LuxNB(int i ,String s){ | |
super(i,s); | |
} | |
double cost(){ | |
return b.getCost()+c.getCost()+2000; | |
} | |
} | |
public class JPA06_2 { | |
public static void main(String args[]){ | |
BasicNB bc = new BasicNB(1,"basic"); | |
System.out.println("商用電腦成本: " + bc.cost()); | |
System.out.println("商用電腦售價: " + bc.price()); | |
LuxNB lc = new LuxNB(2,"Lux"); | |
System.out.println("高階雙核心電腦成本: " + lc.cost()); | |
System.out.println("高階雙核心電腦售價: " + lc.price()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ JAVA6 - 607_3 */ | |
public class JPA06_3 { | |
public static void main(String[] arge){ | |
int[][] n ={ | |
{120,420,315,250,418,818,900}, | |
{312,183,215,89,83,600,700}, | |
{215,500,430,210,300,918,880} | |
}; | |
String[] nn={"北部","中部","南部"}; | |
System.out.println("\n\t 第一電腦科技公司週報表 ( 單 位 : 萬 元 ) "); | |
System.out.println( "直營店 \t 一 \t 二 \t 三 \t 四 \t 五 \t六 \t 日 \t "); | |
System.out.println( "=====\t====\t====\t====\t====\t====\t====\t===="); | |
//主要是使用兩層的for loop,第一層主要是顯示區域,第二層顯示總營業額 | |
for(int a=0;a<3;a++){ | |
System.out.print(nn[a]+"\t"); | |
for(int b=0;b<7;b++){ | |
System.out.print(n[a][b]+"\t"); | |
} | |
System.out.println(""); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ JAVA6 - 607_4 */ | |
public class JPA06_4 { | |
public static void main(String[] arge){ | |
String[] map = { "北部" , "中部" , "南部" }; | |
int[][] salary = { | |
{ 120, 420, 315, 250, 418, 818, 900 }, | |
{ 312, 183, 215, 89, 83, 600, 700 }, | |
{ 215, 500, 430, 210, 300, 918, 880 } | |
}; | |
int cost[] = {180, 200, 360}; | |
int cost1[] = {1500, 1515, 1858}; | |
int sum[] = {0, 0, 0}; | |
double data[] = {0, 0, 0}; | |
int i , j , i_max=3; | |
double ratio; | |
//透過兩層的for loop計算出各店的總營業額 | |
for(int b=0;b<salary.length;b++){ | |
for(int a=0;a<salary[b].length;a++){ | |
sum[b]+=salary[b][a]; | |
} | |
} | |
//計算每家的毛利率 | |
for(int a = 0;a<data.length;a++){ | |
data[a]=((sum[a]-cost[a]-cost1[a])/(double)(cost[a]+cost1[a])*100); | |
} | |
//顯示出資料 | |
for( i = 0 ; i < i_max ; i++ ){ | |
System.out.print("第"+(i+1)+"間直營店銷售總成本="+(cost[i]+cost1[i])+"\n"); | |
System.out.print("銷售總營業額="+sum[i]+"\n"); | |
ratio = data[i]; | |
System.out.printf("銷售銷售毛利=%.2f",ratio); | |
System.out.print("%\n"); | |
System.out.println(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ JAVA6 - 607_5 */ | |
public class JPA06_5 { | |
public static void main(String[] arge){ | |
int[][] salary = { | |
{ 120 , 420 , 315 , 250 , 418,818,900 }, | |
{ 312 , 183 , 215 , 89 , 83,600,700 }, | |
{ 215 , 500 , 430 , 210 , 300,918,880 } | |
}; | |
int cost,sum=0; | |
double ratio; | |
cost=1500+1515+1858+180+200+360; | |
//利用兩層的for loop計算出總營業額 | |
for(int b=0;b<salary.length;b++){ | |
for(int a=0;a<salary[b].length;a++){ | |
sum+=salary[b][a]; | |
} | |
} | |
//計算出毛利率 | |
ratio=(double)(sum-cost)/cost*100; | |
System.out.print("總銷售總成本="+cost); | |
System.out.println(); | |
System.out.print("總銷售總營業額="+sum); | |
System.out.println(); | |
System.out.printf("總銷售銷售毛利率=%.2f",ratio); | |
System.out.print("%"); | |
System.out.println(); | |
} | |
} |
TQC+ JAVA6 試題總覽:LINK
Github 備份:LINK
本篇教學的程式碼皆由筆者編輯,歡迎轉貼本教學,但請全文轉貼,謝啦~
沒有留言:
張貼留言