播放代码

1.film.java



public class Film {
private String type;//类型:恐怖片,爱情等
private String name;//名称
private String director;//导演
private String actor;//主演


    
public String getType() {
return type;
}


public void setType(String type) {
this.type = type;
}


public String getName() {
return name;
}


public void setName(String name) {
this.name = name;
}


public String getDirector() {
return director;
}


public void setDirector(String director) {
this.director = director;
}


public String getActor() {
return actor;
}


public void setActor(String actor) {
this.actor = actor;
}


public Film(){
   
    }
    
    public Film(String type){
    this.type=type;
    }
    
    public Film(String type,String name,String director,String actor){
    this.type=type;
    this.name=name;
    this.director=director;
    this.actor=actor;
    }
    
    public String display(){
    String msg="影片类型:"+type+"\n片名:"+name+"\n导演:"+director+"\n主演:"+actor;
    System.out.println("影片类型:"+type+"\n片名:"+name+"\n导演:"+director+"\n主演:"+actor);
    return msg;
      }
    }


2.film test.java



public class FlimTest {


/**
* @param args
*/
public static void main(String[] args) {

Film one =new Film();
/*one.type="枪战片";
one.name="让子弹飞";
one.director="姜文";
one.actor="姜文,周润发,葛优";*/

one.setType("枪战片");
one.setName("让子弹飞");
one.setDirector("姜文");
one.setActor("姜文,周润发,葛优");


System.out.println(one.display());
System.out.println("*******************************************");

Film two=new Film("爱情片" , "不能说的秘密" , "周杰伦" , "周杰伦,黄秋生,桂纶镁");
        String msg=two.display();
        System.out.println(msg);
}


}


3.person.java

/**
 * 人类:
 * 属性:姓名,性别,年龄
 * 方法:吃饭,行动,工作,说话
 */
public class Person {
    public String name;//姓名
    public String gender;//性别
    public int age;//年龄
    
    public void eat(String name){
    System.out.println(this.name+"邀请"+name+"共进晚餐");
    }
    public void work(){
    System.out.println(name+"的工作理念:干活挣钱有饭吃");
    }
    
    public void work(String contect){
    System.out.println(name+"的工作理念:"+contect);
    }
    
}

4.person test.java

import java.util.Scanner;
public class PersonTest {


/**
* @param args
*/
public static void main(String[] args) {
/*Person hanbing =new Person();
hanbing.name="韩冰";
hanbing.gender="女";
hanbing.age=22;

hanbing.eat("刘顿");
hanbing.work();*/
System.out.println("大家好,欢迎您来到地球村");
Person guest = new Person();//创建对象
Scanner input = new Scanner(System.in);
System.out.print("请输入您的名字:");
String name = input.nextLine();
guest.name=name;//为对象的名称赋值
System.out.print("请选择您的性别:(1,男2,女)");
switch (input.nextInt()){
case 1:
guest.gender = "男";//为对象的性别赋值
break;
case 2:
guest.gender = "女";//为对象的性别赋值
break;
default :
System.out.println("操作错误");
return;
}
System.out.print("请输入您的年龄:");
guest.age=input.nextInt();//为对象的年龄赋值
guest.work();
System.out.print("请重新输入您的工作理念:");
String contect=input.next();
guest.work(contect);

System.out.println("********************************");



}


}

5.player.java



public class Player {
    public String brand;//品牌
    public String type;//类型
    
    public Player(){
   
   
    }
    
    public Player(String brand,String type){
    this.brand=brand;
    this.type=type;
   
    }
    
    public void play(){
    Film two=new Film("爱情片" , "不能说的秘密" , "周杰伦" , "周杰伦,黄秋生,桂纶镁");
    System.out.println(two.display());
    System.out.println("影片开始播放... ...");
    }
    public void play(String film,String director,String actor){
    System.out.println("名片:"+film+"\n导演"+director+"\n主演"+actor);
    System.out.println("影片开始播放... ...");
    }
    public void stop(){
    System.out.println("结束播放,谢谢观看!");
    }
}

6.player test.java

import java.util.Scanner;
public class PlayerTest {


/**
* @param args
*/
public static void main(String[] args) {
System.out.print("请选择需要播放的影片类型:(1.爱情片 2.动作片)");
Scanner input=new Scanner(System.in);
        
Player myPlay=new Player("飞利浦","DVP3310");
switch(input.nextInt()){
case 1:
Film film=new Film();
film.setType("爱情片");
System.out.print("请选择影片名称:(1.山楂树之恋2.手机");
if(input.nextInt()==1){
film.setName("山楂树之恋");
film.setDirector("张艺谋");
film.setActor("周冬雨,窦骁");
}else{
film.setName("手机");
film.setDirector("冯小刚");
film.setActor("葛优,范冰冰");
}
myPlay.play(film.getName(),film.getDirector(),film.getActor());
break;
case 2:
Film one=new Film();
one.setType("动作片");
one.setName("让子弹飞");
one.setDirector("姜文");
one.setActor("姜文,周润发,葛优");

myPlay.play(one.getName(),one.getDirector(),one.getActor());
break;
default:
myPlay.play();
}
       myPlay.stop();
}
}







你可能感兴趣的:(java基础)