用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

计算机类

2018-10-13 作者: 不吃鱼举报

[java]代码库

import java.util.*; 
public class Main{ 
    public static void main(String[] args) { 
         Scanner scan = new Scanner(System.in);
         String model = scan.next();
         double fre = scan.nextDouble();
         int cores = scan.nextInt();
         CPU cpu1 = new CPU(model, fre, cores);
         
         model = scan.next();
         Mainboard mb1 = new Mainboard(model);
         
         model = scan.next();
         int size = scan.nextInt();
         Memory me1 = new Memory(model, size);
         
         model = scan.next();
         size = scan.nextInt();
         Screen sc1 = new Screen(model, size);
         
         model = scan.next();
         String cap = scan.next();
         Harddisk h1 = new Harddisk(model, cap);
         
         Computer com1 = new Computer(cpu1, mb1, me1, sc1, h1);
         
        		 
         model = scan.next();
         fre = scan.nextDouble();
         cores = scan.nextInt();
         CPU cpu2 = new CPU(model, fre, cores);
         
         model = scan.next();
         Mainboard mb2 = new Mainboard(model);
         
         model = scan.next();
         size = scan.nextInt();
         Memory me2 = new Memory(model, size);
         
         model = scan.next();
         size = scan.nextInt();
         Screen sc2 = new Screen(model, size);
         
         model = scan.next();
         cap = scan.next();
         Harddisk h2 = new Harddisk(model, cap);	
         
         Computer com2 = new Computer(cpu2, mb2, me2, sc2, h2);
         System.out.println(com1.equals(com2));
         System.out.println("Computer1:\n"+com1.toString());
         System.out.println("Computer2:\n"+com2.toString());
         
         
         scan.close();  
    } 
}  

class Computer{
	CPU cpu;
	Mainboard mb;
	Memory me;
	Screen sc;
	Harddisk h;
	public Computer(CPU c, Mainboard _mb, Memory _me, Screen _sc, Harddisk _h) {
		cpu = c;
		mb = _mb;
		me = _me;
		sc = _sc;
		h = _h;
	}
	public boolean equals(Computer com) {
		if( cpu.equals(com.cpu) && mb.equals(com.mb) && me.equals(com.me) && sc.equals(com.sc) && h.equals(com.h) )
			return true;
		else
			return false;
	}
	public String toString() {
		return cpu.toString()+mb.toString()+me.toString()+sc.toString()+h.toString();
	}
}

class CPU{
	String model;
	double frequency;
	int cores;
	public CPU(String m, double f, int c) {
		model = m;
		frequency = f;
		cores = c;
	}
	public boolean equals(CPU cpu){
		if(this.model.equals(cpu.model)&&(this.frequency == cpu.frequency)&&(this.cores==cpu.cores)) {
			return true;
		}
		else
			return false;
	}
	public String toString() {
		return "CPU:\n" +"Model: " +model +"\n" +"Frequency: " +String.format("%.1f",frequency) +"\n" +"Number of Cores: " +cores +"\n";
	}
}

class Mainboard{
	String model;
	public Mainboard(String m) {
		model = m;
	}
	public boolean equals(Mainboard mb) {
		if(this.model.equals(mb.model))
			return true;
		else
			return false;
	}
	public String toString() {
		return "Mainboard:\n" +"Model: " +model +"\n";
	}
}

class Memory{
	String model;
	int size;
	public Memory(String m, int s) {
		model = m;
		size = s;
	}
	public boolean equals(Memory me) {
		if(this.model.equals(me.model) && (this.size==me.size))
			return true;
		else
			return false;
	}
	public String toString() {
		return "Memory:\n" +"Model: " +model +"\n" +"Size: " +size +"\n";
	}
}

class Screen{
	String model;
	int size;
	public Screen(String m, int s) {
		model = m;
		size = s;
	}
	public boolean equals(Screen sc) {
		if(this.model.equals(sc.model) && (this.size==sc.size))
			return true;
		else
			return false;
	}
	public String toString() {
		return "Screen:\nModel: " +model +"\n" +"Size: " +size +"\n";
	}
}

class Harddisk{
	String model;
	String size;
	public Harddisk(String m, String s) {
		model = m;
		size = s;
	}
	public boolean equals(Harddisk h) {
		if(this.model.equals(h.model) && this.size.equals(h.size))
			return true;
		else
			return false;
	}
	public String toString() {
		return "Harddisk:\nModel: " +model +"\n" +"Size: " +size;
	}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...