[java]代码库
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String cm = scan.next();
double f = scan.nextDouble();
int c = scan.nextInt();
String mainm = scan.next();
String mem = scan.next();
int ms = scan.nextInt();
String sm = scan.next();
int ss = scan.nextInt();
String hm = scan.next();
int hs = scan.nextInt();
Computer c1 = new Computer(cm,f,c,mainm,mem,ms,sm,ss,hm,hs);
cm = scan.next();
f = scan.nextDouble();
c = scan.nextInt();
mainm = scan.next();
mem = scan.next();
ms = scan.nextInt();
sm = scan.next();
ss = scan.nextInt();
hm = scan.next();
hs = scan.nextInt();
Computer c2 = new Computer(cm,f,c,mainm,mem,ms,sm,ss,hm,hs);
System.out.println(c1.equals(c2));
System.out.println("Computer1:");
System.out.println(c1.toString());
System.out.println("Computer2:");
System.out.println(c2.toString());
scan.close();
}
}
class Computer
{
String CPUmodel;
double Frequency;
int Cores;
String Mainboardmodel;
String Memorymodel;
int Memorysize;
String Screenmodel;
int Screensize;
String Harddiskmodel;
int Harddisksize;
public Computer(String cm, double f, int c, String mainm, String mem, int ms, String sm, int ss, String hm, int hs)
{
CPUmodel = cm;
Frequency = f;
Cores = c;
Mainboardmodel = mainm;
Memorymodel = mem;
Memorysize = ms;
Screenmodel = sm;
Screensize = ss;
Harddiskmodel = hm;
Harddisksize = hs;
}
String getCPUmodel()
{
return CPUmodel;
}
double getFrequency()
{
return Frequency;
}
int getCores()
{
return Cores;
}
String getMainboardmodel()
{
return Mainboardmodel;
}
String getMemorymodel()
{
return Memorymodel;
}
int getMemorysize()
{
return Memorysize;
}
String getScreenmodel()
{
return Screenmodel;
}
int getScreensize()
{
return Screensize;
}
String getHarddiskmodel()
{
return Harddiskmodel;
}
int getHarddisksize()
{
return Harddisksize;
}
boolean equals(Computer c)
{
if(!CPUmodel.equals(c.getCPUmodel()))
return false;
else if( !(Frequency == c.getFrequency() ) )
return false;
else if( !(Cores == c.getCores() ) )
return false;
else if(!Mainboardmodel.equals(c.getMainboardmodel()))
return false;
else if(!Memorymodel.equals(c.getMemorymodel()))
return false;
else if( !(Memorysize == c.getMemorysize() ) )
return false;
else if(!Screenmodel.equals(c.getScreenmodel()))
return false;
else if( !(Screensize == c.getScreensize() ) )
return false;
else if(!Harddiskmodel.equals(c.getHarddiskmodel()))
return false;
else if( !(Harddisksize == c.getHarddisksize() ) )
return false;
else
return true;
}
public String toString()
{
return "CPU:\nModel: "+CPUmodel+"\nFrequency: "+String.format("%.1f",Frequency)+"\nNumber of Cores: "+Cores+"\nMainboard:\nModel: "+Mainboardmodel+"\nMemory:\nModel: "+Memorymodel+"\nSize: "+Memorysize+"\nScreen:\nModel: "+Screenmodel+"\nSize: "+Screensize+"\nHarddisk:\nModel: "+Harddiskmodel+"\nSize: "+Harddisksize;
}
}