java小白自学笔记——Day3

例1:编写猫类,创建三只猫的对象,并让它们一起抓老鼠

   代码如下:

package project;
public class cat {
	String color;
	
	public cat(String color)
	{
		this.color=color;
	}
	
	public static void main(String[] args) {
		cat cat1=new cat("black");
		cat cat2=new cat("white");
		cat cat3=new cat("yellow");
		System.out.println(cat1.color+"、"+cat2.color+"、and"+" "+cat3.color+" "+"cat catch mouse todether!");
	}			
}

例2:创建工具类,类中调动pow()类,并计算4.56和3.5的四次幂

   代码如下:

package project;
public class gongju{
	double x;
	
	public static double pow(double x)
	{
		return x*x*x*x;
	}
	
	public static void main(String[] args) {
		double y=pow(4.56);
		System.out.println("4.56的三次幂是:"+y);
		double z=pow(3.5);
		System.out.println("3.5的三次幂是:"+z);
	}			
}

例3:电影票:满18周岁100元全票,未满的享受半价。控制台按姓名、年龄、票价输出以下观众信息(张三,20;李四,16;王五,8;赵六,32)

    代码如下:

package project;
public class MoivePrice {
	String name;
	int age;
	int price;
	
	public MoivePrice(String name,int age)
	{
		this.name=name;
		this.age=age;
		if(age>=18)
		{
			this.price=100;
		}
		else if(age>=0&&age<18)
		{
			this.price=50;
		}
		else
		{
			this.price=0;
		}
	}
	
	public static void main(String[] args) {
		MoivePrice p1=new MoivePrice("张三",20);
		MoivePrice p2=new MoivePrice("李四",16);
		MoivePrice p3=new MoivePrice("王五",8);
		MoivePrice p4=new MoivePrice("赵六",32);
		System.out.println("姓名  年龄  票价(元)");
		System.out.println("________________");
		System.out.println(p1.name+"  "+p1.age+"  "+p1.price);
		System.out.println(p2.name+"  "+p2.age+"  "+p2.price);
		System.out.println(p3.name+"  "+p3.age+"   "+p3.price);
		System.out.println(p4.name+"  "+p4.age+"  "+p4.price);
	}			
}

例4:记录4名学生的语文、数学、英语三科成绩,再计算每个人的平均分(用到成员变量和this关键字)

     代码如下:

package project;
public class ScoresAverage{
	String name;
	double chinese,math,english;
	double average;
	int number;
	
	public  ScoresAverage(int number,String name,double chinese,double math,double english)
	{
		this.number=number;
		this.name=name;
		this.chinese=chinese;
		this.math=math;
		this.english=english;
		this.average=(math+chinese+english)/3;
	}
	
	public static void main(String[] args) {
		 ScoresAverage s1=new  ScoresAverage(1,"张三",91.5,98.0,89.0);
		 ScoresAverage s2=new  ScoresAverage(2,"李四",96.0,98.5,93.0);
		 ScoresAverage s3=new  ScoresAverage(3,"王五",97.0,100.0,98.5);
		 ScoresAverage s4=new  ScoresAverage(4,"赵六",77.0,83.0,81.0);
		
		System.out.println("学号  姓名  语文  数学  英语  平均分");
		System.out.println("____________________________");
		System.out.println(s1.number+"  "+s1.name+"  "+s1.chinese+"  "+s1.math+"  "+s1.english+"  "+s1.average);
		System.out.println(s2.number+"  "+s2.name+"  "+s2.chinese+"  "+s2.math+"  "+s2.english+"  "+s2.average);
		System.out.println(s3.number+"  "+s3.name+"  "+s3.chinese+"  "+s3.math+"  "+s3.english+" "+s3.average);
		System.out.println(s4.number+"  "+s4.name+"  "+s4.chinese+"  "+s4.math+"  "+s4.english+"  "+s4.average);
	}			
}

例5:编写矩形类型,并求出给定矩形的面积

    代码如下:

package project;
import java.util.Scanner;
public class SIZE {
	double LongSide,WideSide;
	double s;
	
	public SIZE(double chang,double kuan)
	{
		this.LongSide=chang;
		this.WideSide=kuan;
		this.s=chang*kuan;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double x=sc.nextDouble();
		double y=sc.nextDouble();
		sc.close();
		SIZE ju=new pro(x,y);
		System.out.println(ju.s);
	}			
}

例6:编写两个数运算的简单计算器类

    代码如下:

package project;
import java.util.Scanner;
public class EasyCalculator {
	char operator;
	double x,y;
	double s;
	
	public EasyCalculator(double x,char yunsuaufu,double y)
	{
		this.x=x;
		this.y=y;
		this.operator=yunsuaufu;
		if(yunsuaufu=='+')
		{
			this.s=x+y;
		}
		else if(yunsuaufu=='-')
		{
			this.s=x-y;
		}
		else if(yunsuaufu=='*')
		{
			this.s=x*y;
		}
		else if(yunsuaufu=='/')
		{
			this.s=x/y;
		}
		else if(yunsuaufu=='%')
		{
			this.s=x%y;
		}
		else
		{
			this.s=0;
		}
		
		}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double x=sc.nextDouble();
		char ch=sc.next().charAt(0);
		double y=sc.nextDouble();
		sc.close();
		EasyCalculator Project=new EasyCalculator(x,ch,y);
		System.out.println(Project.s);
	}			
}

   

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FPGA自学笔记——设计与验证JMB FPGA(可编程逻辑门阵列)是一种可编程的硬件平台,可以实现各种数字电路的设计与验证。本文将简要介绍使用FPGA自学设计与验证JMB(低功耗、高效能、集成度高的多媒体芯片)的过程。 首先,我们需要了解JMB的功能和特性。JMB是一种面向多媒体应用的芯片,具备低功耗、高效能和高集成度的优势。我们需要详细研究JMB的硬件架构和内部模块,包括处理器核、存储器模块、图像和音频处理模块等。 接下来,我们可以使用FPGA开发板来设计和验证JMB。首先,我们需要熟悉FPGA设计工具,例如Vivado或Quartus等。这些工具提供了图形化界面和硬件描述语言(HDL)等设计方法。我们可以使用HDL编写JMB的功能模块,并将其综合为FPGA可执行的位流文件。 在设计完成后,我们需要验证JMB的功能和性能。我们可以使用仿真工具(例如ModelSim或ISE Simulator)来模拟JMB在不同情况下的行为。通过设计测试程序并运行仿真,我们可以验证JMB的各个模块是否正确地工作,是否满足设计要求。 在验证完成后,我们可以将位流文件下载到FPGA开发板中进行智能芯片的物理实现和测试。通过与外部设备的连接以及相关测试程序的运行,我们可以验证JMB在实际硬件中的功能和性能。 总结起来,学习FPGA设计与验证JMB,我们需要熟悉JMB的硬件架构和内部模块,并使用FPGA开发工具进行设计与验证。通过仿真和物理实现测试,我们可以验证JMB的功能和性能。这些过程需要理论知识和实践经验的结合,希望这些笔记能够给你提供一些参考和指导。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值