class NB{
int cost;
NB(){}
NB(int no){
switch(no){
case 1:
cost=10000;break;
case 2:
cost=8500;break;
}
}
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());
}
}
第二題
abstract class CNB{
HD h;
CPU c;
CNB(){}
CNB(int i,String s){
c=new CPU(s);
h= new HD(i);
}
abstract double cost();
double price(){
return cost()*1.5;
}
}
class BasicNB extends CNB{
BasicNB(){}
BasicNB(int i,String s){
super(i,s);
}
double cost(){
return c.getCost()+1000+h.getCost();
}
}
class LuxNB extends CNB{
LuxNB(){}
LuxNB(int i,String s){
super(i,s);
}
double cost(){
return c.getCost()+2000+h.getCost();
}
}
class CPU extends NB{
CPU(){}
CPU(String s){
if(s.equals("basic")){
cost = 1000;
}
else{
cost = 2000;
}
}
}
class HD extends NB{
HD(){}
HD(int i){
if(i==1){
cost=5000;
}
else{
cost=8500;
}
}
}
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());
}
}
第三題
public class JPA06_3 {
public static void main(String[] arge){
int [][]array={{120,420,315,250,418,818,900},
{212,183,215,89,83,600,700},
{215,500,430,210,300,918,880}};
String []name={"北部","中部","南部"};
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(int i =0;i<3;i++){
System.out.printf(name[i]+"\t");
for(int j =0;j<7;j++){
System.out.print(array[i][j]+"\t");
}
System.out.println();
}
}
}
第四題
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[] = {0,0,0};
int sum[] = {0,0,0,0,0,0,0};
int data[] = {0,0,0};
int[][] a_box = salary ;
int i , j , i_max , j_max, min;
double ratio;
int saleCost[]={1500,1515,1858};
int openCost[]={180,200,360};
i_max = 3;
j_max = 7;
for( i = 0 ; i < i_max ; i++ ){
cost[i]= saleCost[i]+openCost[i];
for( j=0 ; j<j_max ; j++ ){
sum[i]+=salary[i][j];
}
ratio=(sum[i]-cost[i])/(double)cost[i]*100;
System.out.print("第"+(i+1)+"間直營店銷售總成本="+cost[i]);
System.out.println();
System.out.print("銷售總營業額="+sum[i]);
System.out.println();
System.out.printf("銷售銷售毛利=%.2f",ratio);
System.out.print("%");
System.out.println();
System.out.println();
}
}
}
第五題
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 i , j , i_max , j_max,cost,sum=0;
double ratio;
i_max = salary.length ;
j_max = salary[0].length ;
cost=1500+1515+1858+180+200+360;
for( i = 0 ; i < i_max ; i++ ){
for( j=0 ; j<j_max ; j++ ){
sum+=salary[i][j];
}
}
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();
}
}
沒有留言:
張貼留言