按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下
创新互联主营祁县网站建设的网络公司,主营网站建设方案,重庆APP软件开发,祁县h5微信小程序搭建,祁县网站营销推广欢迎祁县等地区企业咨询
需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果
Student.java文件代码如下
package user.java.test;
import java.io.Serializable;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private String no;
private String name;
private double score;
public Student(){}
public Student(String no,String name,double score){
this.no=no;
this.name=name;
this.score=score;
}
public String getNo(){ return no;}
public void setNo(String no){ this.no=no;}
public String getName(){ return name;}
public void setName(String name){ this.name=name;}
public double getScore(){ return score;}
public void setScore(double score){ this.score=score;}
public String toString(){
return "学号:"+no+",姓名:"+name+",成绩:"+score;
}
public static double getAvg(Student[] sArray){
double sum=0,avg;
for(int i=0;isArray.length;i++){
sum=sum+sArray[i].getScore();
}
avg=sum/sArray.length;
return avg;
}
}
Test.java文件代码如下
package user.java.test;
public class Test{
public static void main(String[] args){
Student[] sArray=new Student[5];
sArray[0]=new Student("001","张三",89.5);
sArray[1]=new Student("002","李四",82.5);
sArray[2]=new Student("003","王五",93);
sArray[3]=new Student("004","赵六",73.5);
sArray[4]=new Student("005","孙七",66);
System.out.println("这些学生的平均分:"+Student.getAvg(sArray));
for(int i=0;isArray.length;i++){
System.out.println(sArray[i].toString());
}
}
}
//都是从新手过来的,以下代码供参考
//1.
public class BankAccount {
private static String acctnum;
private static double money;
private static void showAcct() {
System.out.println("账号为: " + acctnum);
}
private static void showMoney() {
System.out.println("余额为: " + money);
}
public BankAccount(String acc, double m) {
this.acctnum = acc;
this.money = m;
}
public static void main(String[] args) {
BankAccount ba = new BankAccount("626600018888", 5000.00);
ba.showAcct();
ba.showMoney();
}
}
//2.
public class Triangle {
private static float a;
private static float b;
private static float c;
public Triangle(float a, float b, float c) {
this.a = a;
this.b = b;
this.c = c;
}
public static boolean judgeTriangle(float a, float b, float c) {
if ((a Math.abs(b - c) a b + c)
(b Math.abs(a - c) b a + c)
(c Math.abs(a - b) c a + b))
return true;
else
return false;
}
public float getCircumference() {
return this.a + this.b + this.c;
}
}
//3.
public class TestTriangle {
public static void main(String[] args) {
Triangle t = new Triangle(5.3f,7.8f,9.3f);
if(t.judgeTriangle(5.3f,7.8f,9.3f)){
System.out.print("能够成三角形,周长为: ");
System.out.printf("%9.2f",t.getCircumference());}
else
System.out.println("不能构成三角形");
}
}
最简单的java代码肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!
import java.util.Scanner;
import demo.ui.MainShell;
import demo.ui.PublicStatic;
public class DemoApp {
public static int getScanner() {
int input = 0;
try {
Scanner scanner = new Scanner(System.in);
input = scanner.nextInt();
} catch (Exception e) {
System.out.println("\t\t请重新输入");
return getScanner();
}
return input;
}
public static void main(String[] args) {
System.out.println("\t\t\t欢迎使用系统");
System.out.println("\t\t***********************");
System.out.println("\t\t\t1、客户信息管理");
System.out.println("\t\t\t2、购物结算");
System.out.println("\t\t\t3、真情回馈");
System.out.println("\t\t\t4、注销");
System.out.println("\t\t***********************");
while(true) {
int input = getScanner();
switch (input) {
case 1:
System.out.println("\t\t\t1、客户信息管理");
break;
case 2:
System.out.println("\t\t\t2、购物结算");
break;
case 3:
System.out.println("\t\t\t3、真情回馈");
break;
case 4:
System.out.println("\t\t\t4、注销");
break;
default:
System.out.println("\t\t请重新输入");
break;
}
if(input == 4) {
break;
}
}
}
}
public class test1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入本月税前工资");
double d = scan.nextDouble(); //税前工资
double sal= d - 3500; // 减去扣除数的
double salary = 0; //初始化工资
if(sal=1500){
salary = sal*0.03;
}else if(sal=4500){
salary = sal*0.1-105;
}else if(sal=9000){
salary = sal*0.2-555;
}else if(sal=35000){
salary = sal*0.25-1005;
}else if(sal=55000){
salary = sal*0.3-2755;
}else if(sal=80000){
salary = sal*0.35-5505;
}else{
salary = sal*0.45-13505;
}
System.out.println("个人所得税的缴纳额度为:"+salary+"元");
}
}
尽量简化逻辑 像钱的多少 先用变量存储起来 再带入就好了
尽量简化代码 像输出也只用一句然后带入就好了
尽量自己考虑 每一点问题都是自己敲代码的过程中产生然后明白的
这题是我原题 我知道你在哪 既然在那了 为什么还不努力呢
public class Compute{
public static void main(String args [])
{
int a = 2;
float b = 2;
double c = 2;
Compute com1 = new Compute();
System.out.println(com1.mySqr(a));
System.out.println(com1.mySqr(b));
System.out.println(com1.mySqr(c));
}
public int mySqr(int x)
{
int value = x*x;
return value;
}
public float mySqr(float x)
{
float value = x*x;
return value;
}
public double mySqr(double x)
{
double value = x*x;
return value;
}
}