java电视代码 java 代码
java语言编写一个电视机类
public class TV {
创新互联公司10多年企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,企业网站建设及推广,对成都iso认证等多个行业拥有多年的营销推广经验的网站建设公司。
private int channel;
private int volumn;
public TV() {
channel = 0;
volumn = 10;
}
public TV(int channel, int volumn) {
this.channel = channel;
this.volumn = volumn;
}
public void setChannel(int channel) {
this.channel = channel;
}
public void setVolumn(int volumn) {
this.volumn = volumn;
}
public void ChannelPlus() {
this.channel++;
}
public void VolumnPlus() {
this.volumn++;
}
}
(1)和(2)是构造器,不是方法,题目的表达不对……
哥们儿,这题不难一看就没好好学习,努力学习吧,只能帮你到这里了……
有关接口回调的java题,求解。
下面是UnitPrice接口代码:
public interface UnitPrice {
public double unitprice();
}
下面是电视机类代码:
public class Television implements UnitPrice {
@Override
public double unitprice() {
return 3500d;
}
}
下面是计算机类代码:
public class Computer implements UnitPrice {
@Override
public double unitprice() {
return 7800d;
}
}
下面是手机类代码:
public class Mobile implements UnitPrice {
@Override
public double unitprice() {
return 2500d;
}
}
下面是公共类代码:
import java.util.Scanner;
public class Common {
static double get(UnitPrice u) {
return u.unitprice();
}
@SuppressWarnings("resource")
public static void main(String[] args) {
System.out.print("请输入电视机的销售个数:");
Scanner scanner = new Scanner(System.in);
int television_num = scanner.nextInt();
System.out.print("请输入计算机的销售个数:");
scanner = new Scanner(System.in);
int computer_num = scanner.nextInt();
System.out.print("请输入手机的销售个数:");
scanner = new Scanner(System.in);
int mobile_num = scanner.nextInt();
double television_price = television_num * (get(new Television()));
System.out.println("电视机的销额是:" + television_price);
double computer_price = computer_num * (get(new Computer()));
System.out.println("计算机的销额是:" + computer_price);
double mobile_price = mobile_num * (get(new Mobile()));
System.out.println("手机的销额是:" + mobile_price);
System.out.println("总销额是:" + (television_price + computer_price + mobile_price));
scanner.close();
}
}
下面是执行后的效果截图:
麻烦您看一下,是否能够满足要求。
编写java应用程序模拟电视机,实现TV电视机类,要求用ChannelArray数组放置电视机的
//TV类
public class Tv {
public void open(){
System.out.println("打开电视机");
}
public void close(){
System.out.println("关闭电视机");
}
public void search(int x){
System.out.println("您搜索到的是"+x+"号频道");
}
public void ctrlVol(String s){
int vol=10;
if(s.equals("+"))
vol++;
if(s.equals("-"))
vol--;
System.out.println("当前音量为"+vol);
}
public void changeChannel(int x){
if( x 29 )
System.out.println("没有该频道");
else
System.out.println("当前"+x+"号频道");
}
public void changeChannel(String s){
int x=0;
if(s.equals("+"))
x++;
if(s.equals("-"))
x--;
System.out.println("当前"+x+"号频道");
}
}
//Controller遥控器类
public class Controller{
public void openTv(Tv tv){
tv.open();
}
public void closeTv(Tv tv){
tv.close();
}
public void searchTv(Tv tv){
int x=(int)(Math.random()*30);
tv.search(x);
}
public void ctrlTvVol(Tv tv){
tv.ctrlVol("+");
}
public void changeTvChannel(Tv tv){
tv.changeChannel("+");
tv.changeChannel(23);
}
}
Java题目,怎么定义定义一个电视机类?
public class TV {
public static void main(String[] args) {
TV tv = new TV("海信", 5000, 56);
tv.turnOn();
tv.turnOff();
}
private String brand;
private double price;
private int size;
public TV() {
}
public TV(String brand, double price, int size) {
this.brand = brand;
this.price = price;
this.size = size;
}
public void turnOn() {
System.out.println("欢迎使用" + this.getBrand() + "电视机...");
}
public void turnOff() {
System.out.println("再见");
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
网站标题:java电视代码 java 代码
本文来源:http://pwwzsj.com/article/dohsdpo.html