189 8069 5689

java课堂实训代码,Java程序设计实训

急!!!JAVA课堂实验编程,求答案!!追分急!!

纯手打,2.(3)没搞清那个命令行是什么意思,所以没写

10年积累的成都网站制作、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有盱眙免费网站建设让你可以放心的选择与我们合作。

package student;

public class Student {

private String college;

private String major;

private String classes;

private String name;

private int oop;

private int network;

private int sql;

private int sum;

//无参构造函数

public Student(){}

//有参构造函数

public Student( String college,

String major, String classes,

String name, int oop, int network,

int sql) {

super();

this.college = college;

this.major = major;

this.classes = classes;

this.name = name;

this.oop = oop;

this.network = network;

this.sql = sql;

}

//成员方法

public int sum(){

return oop+network+sql;

}

//getter,setter方法

public String getCollege() {

return college;

}

public void setCollege(String college) {

this.college = college;

}

public String getMajor() {

return major;

}

public void setMajor(String major) {

this.major = major;

}

public String getClasses() {

return classes;

}

public void setClasses(String classes) {

this.classes = classes;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getOop() {

return oop;

}

public void setOop(int oop) {

this.oop = oop;

}

public int getNetwork() {

return network;

}

public void setNetwork(int network) {

this.network = network;

}

public int getSql() {

return sql;

}

public void setSql(int sql) {

this.sql = sql;

}

//toString方法

@Override

public String toString() {

return "姓名:"+getName()+" "+"学院:"+getCollege()+" "+"专业:"+getMajor()

+" "+"班级"+getClasses()+" "+"总成绩:"+sum();

}

}

//测试类

package student;

import java.util.Scanner;

public class MyStudent {

public static void main(String[] args) {

//2.(1)

Student s=new Student();

s.setName("张三");

s.setCollege("南大");

s.setMajor("软件技术");

s.setClasses("软件1班");

s.setOop(89);

s.setNetwork(86);

s.setSql(99);

System.out.println(s);

System.out.println("------------------------------------"

+ "--------------------------------------");

//2.(2)

Student s1=new Student("南大","软件技术","软件1班","李四", 88,98, 91);

System.out.println(s1);

System.out.println("-------------------------------"

+ "-----------------------------------------");

//2.(3)

Scanner a=new Scanner(System.in);

System.out.println("请输入学院:");

String college=a.next();

System.out.println("请输入专业:");

String major=a.next();

System.out.println("请输入班级:");

String classes=a.next();

System.out.println("请输入姓名:");

String name=a.next();

System.out.println("请输入面向对象程序设计成绩:");

int oop=a.nextInt();

System.out.println("请输入网络原理成绩:");

int network=a.nextInt();

System.out.println("请输入姓名数据库成绩:");

int sql=a.nextInt();

Student s2=new Student(college,major,classes,name,oop,network,sql);

System.out.println(s2);

}

}

java实验题,求代码和运行方式!

下面是第一题,采纳此答案发第二题代码

========分割线=========

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class Q1 {

public static void main(String[] args) {

try {

Scanner scanner=new Scanner(System.in);

String data = scanner.nextLine();

File file = new File("java\\code");

if (!file.exists()) {

file.mkdirs();

}

File file1=new File(file,"mydata.txt");

if (!file1.exists()) {

file1.createNewFile();

}

FileWriter fw = new FileWriter(file1.getAbsoluteFile());

BufferedWriter bw = new BufferedWriter(fw);

bw.write(data);

bw.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

java代码示例

importjava.awt.*;importjava.awt.event.*;classShopFrameextendsFrameimplementsActionListener{Labellabel1,label2,label3,label4;Buttonbutton1,button2,button3,button4,button5;TextAreatext;Panelpanel1,panel2;staticfloatsum=0.0f;ShopFrame(Strings){super(s);setLayout(newBorderLayout());label1=newLabel("面纸:3元",Label.LEFT);label2=newLabel("钢笔:5元",Label.LEFT);label3=newLabel("书:10元",Label.LEFT);label4=newLabel("袜子:8元",Label.LEFT);button1=newButton("加入购物车");button2=newButton("加入购物车");button3=newButton("加入购物车");button4=newButton("加入购物车");button5=newButton("查看购物车");text=newTextArea("商品有:"+"\n",5,10);text.setEditable(false);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);button4.addActionListener(this);button5.addActionListener(this);panel1=newPanel();panel2=newPanel();panel1.add(label1);panel1.add(button1);panel1.add(label2);panel1.add(button2);panel1.add(label3);panel1.add(button3);panel1.add(label4);panel1.add(button4);panel2.setLayout(newBorderLayout());panel2.add(button5,BorderLayout.NORTH);panel2.add(text,BorderLayout.SOUTH);this.add(panel1,BorderLayout.CENTER);this.add(panel2,BorderLayout.SOUTH);setBounds(100,100,350,250);setVisible(true);validate();}publicvoidactionPerformed(ActionEvente){if(e.getSource()==button1){text.append("一个面纸、");sum=sum+3;}elseif(e.getSource()==button2){text.append("一只钢笔、");sum=sum+5;}elseif(e.getSource()==button3){text.append("一本书、");sum=sum+10;}elseif(e.getSource()==button4){text.append("一双袜子、");sum=sum+8;}elseif(e.getSource()==button5){text.append("\n"+"总价为:"+"\n"+sum);}}}publicclassShopping{publicstaticvoidmain(String[]args){newShopFrame("购物车");}}我没用Swing可能显示不出来你的效果。不满意得话我在给你编一个。

Java实验,代码怎么写?

Shape.java接口代码

public interface Shape {

public static final double PI = 3.14d;

public double area();

}

Circle.java圆类代码

public class Circle implements Shape {

private double radius;

public Circle(double radius) {

  this.radius = radius;

}

@Override

public double area() {

  return PI * this.radius * this.radius;

}

public double perimeter() {

  return 2 * PI * this.radius;

}

}

Cylinder.java圆柱体类代码

public class Cylinder extends Circle {

private double height;

public Cylinder(double radius, double height) {

  super(radius);

  this.height = height;

}

public double area() {

  return 2 * super.area() + super.perimeter() * this.height;

}

public double volume() {

  return super.area() * this.height;

}

}

X5_3_6.java主类代码

public class X5_3_6 {

public static void main(String[] args) {

  Circle cir1 = new Circle(5);

  System.out.println("圆的面积为:" + cir1.area());

  System.out.println("圆的周长为:" + cir1.perimeter());

  Cylinder cy1 = new Cylinder(10, 15);

  System.out.println("圆柱体的表面积为:" + cy1.area());

  System.out.println("圆柱体的体积为:" + cy1.volume());

}

}

上面是我写的代码,下图是执行结果,麻烦看一下,是否可以。


当前文章:java课堂实训代码,Java程序设计实训
文章源于:http://cdxtjz.cn/article/dsioceg.html

其他资讯