1. 程式人生 > >第三章課後作業

第三章課後作業

  第三章 課後作業
上機練習2:錄入會員資訊
package com.bdqn.dome;
  import java.util.Scanner;
public class dome3 {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 
 System.out.println("MySopping管理系統<客戶資訊<新增客戶資訊\n");
 
  System.out.print("請輸入會員號");
  int vipnum =input.nextInt();
  
  System.out.print("請輸入會員生日");
  String vipbdy = input.next();
  
  System.out.print("請輸入會員積分");
  int teg = input.nextInt();
  
  if(vipnum<1000||vipnum>9999) {
   System.out.println("輸入有誤請重新輸入。");
  }else {
   System.out.println("您錄入的會員資訊是\n"+vipnum+"\t"+vipbdy+"\t"+teg);
  }
  System.out.println("程式結束");
 }
 }
上機練習4:計算會員折扣
package com.excellence.action;
  import java.util.Scanner;public class CalcDiscounnt {
 public static void main(String[] args) {
  Scanner input=new Scanner(System.in);
  System.out.print("請輸入會員積分:");
  int integral =input.nextInt();
  if (integral>=8000) {
   System.out.println("六折");
  }
  else if (integral>=4000) {
   System.out.println("七折");
  }
  else if (integral>=2000) {
   System.out.println("八折");
  }
  else {
   System.out.println("九折");
  }
 } }
簡答題
第一題
package tz1;import java.util.Scanner;public class demo5 {
 public static void main(String[] args) {
  String name ="青";
  int pas=123;
  Scanner input=new Scanner(System.in);
  System.out.println("請輸入你都使用者名稱:");
     name=input.next();
     System.out.println("請輸入你的密碼:");
     pas=input.nextInt();
  if (name.equals("青")&&pas==123)  {
   System.out.print("歡迎你,青"); 
  }
  else {
   System.out.print("對不起,你不是青");
  }
 } }
第二題
package tz1;
  import java.util.Scanner;
public class demo6 {
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.print("請輸入年齡:");
  int age = input.nextInt();
  System.out.print("請輸入性別:");
  String gender = input.next();
  
  if (age>=5 && gender.equals("男") ) {
   System.out.println("可以搬動桌子");
   
  }
 } }
第三題
package tz1;
  import java.util.Scanner;public class demo7 {
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.println("請輸入3個整數:");
  int a = input.nextInt();
  int b = input.nextInt();
  int c = input.nextInt();
  if (a < b && a < c) {
   if (b < c) {
    System.out.print(a   +b +c);
   }   else {    System.out.print(a + "," + c + "," + b);
   }
  } else if (b < a && b < c) {
   if (a < c) {
    System.out.println(b + "," + a + "," + c);
   } else {
    System.out.print(b + "," + c + "," + a);   }
  } else {
   if (a < b) {
    System.out.print(c + "," + a + "," + b);
   } else {
    System.out.print(c + "," + b + "," + a);
   
   }
  }
 
   }
  }
第四題
package tz1;
 import java.util.Scanner;
public class demo8 {
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.println("請輸入一個整數:");
  int age= input.nextInt();
  if (age/3==0 && age/5==0) {
   System.out.println("該整數是3或5的倍數");}
   else  {
    System.out.println("該數不能被3或5中的任何一個整除");
   }
   
  }
  
  }
第五題
package tz1;
   import java.util.Scanner;public class dome12 {
 public static void main(String[] args) {
  System.out.println("請輸入成績:");
  Scanner input = new Scanner(System.in);
  int score = input.nextInt();
       if (score==100) {
   System.out.println("父親給她買車");
  }else if (score>=90) {
   System.out.println("母親給她買膝上型電腦");
  }else if (score>=60) {
   System.out.println("母親給她買手機");
  }else {
   System.out.println("沒有禮物");
  }}
}第六題
package tz1;import java.io.OutputStreamWriter;
import java.util.Scanner;import org.omg.CORBA_2_3.portable.OutputStream;public class demo9 {
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  int plane = 5000;
  System.out.println("請輸入您要出行的月份:1~12");
  int Month = input.nextInt();  System.out.println("請問您選擇頭等艙還是經濟艙?頭等艙輸入1,經濟艙輸入2");
  int choice = input.nextInt();
  // 條件一
  if (Month >= 4 && Month <= 10) {// 如果月份大於或等於4並且小於或等於10
   // 條件二
   if (choice == 1) {// 選擇1
    // 程式碼一
    System.out.println(plane * 0.9);// 票價為5000*0.9   } else {
    // 程式碼二
    System.out.println(plane * 0.8);
   }
  }  if (Month < 4 || Month > 10) {// 如果月份小於4或者大於10
   if (choice == 1)// 選擇1
   {
    System.out.println(plane * 0.5);
   } else {
    System.out.println(plane * 0.4);
   }
  } }}