純手打,2.(3)沒(méi)搞清那個(gè)命令行是什么意思,所以沒(méi)寫(xiě)

10年積累的成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有盱眙免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
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;
//無(wú)參構(gòu)造函數(shù)
public Student(){}
//有參構(gòu)造函數(shù)
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()+" "+"學(xué)院:"+getCollege()+" "+"專業(yè):"+getMajor()
+" "+"班級(jí)"+getClasses()+" "+"總成績(jī):"+sum();
}
}
//測(cè)試類
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("軟件技術(shù)");
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("南大","軟件技術(shù)","軟件1班","李四", 88,98, 91);
System.out.println(s1);
System.out.println("-------------------------------"
+ "-----------------------------------------");
//2.(3)
Scanner a=new Scanner(System.in);
System.out.println("請(qǐng)輸入學(xué)院:");
String college=a.next();
System.out.println("請(qǐng)輸入專業(yè):");
String major=a.next();
System.out.println("請(qǐng)輸入班級(jí):");
String classes=a.next();
System.out.println("請(qǐng)輸入姓名:");
String name=a.next();
System.out.println("請(qǐng)輸入面向?qū)ο蟪绦蛟O(shè)計(jì)成績(jī):");
int oop=a.nextInt();
System.out.println("請(qǐng)輸入網(wǎng)絡(luò)原理成績(jī):");
int network=a.nextInt();
System.out.println("請(qǐng)輸入姓名數(shù)據(jù)庫(kù)成績(jī):");
int sql=a.nextInt();
Student s2=new Student(college,major,classes,name,oop,network,sql);
System.out.println(s2);
}
}
下面是第一題,采納此答案發(fā)第二題代碼
========分割線=========
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();
}
}
}
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("書(shū):10元",Label.LEFT);label4=newLabel("襪子:8元",Label.LEFT);button1=newButton("加入購(gòu)物車");button2=newButton("加入購(gòu)物車");button3=newButton("加入購(gòu)物車");button4=newButton("加入購(gòu)物車");button5=newButton("查看購(gòu)物車");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("一個(gè)面紙、");sum=sum+3;}elseif(e.getSource()==button2){text.append("一只鋼筆、");sum=sum+5;}elseif(e.getSource()==button3){text.append("一本書(shū)、");sum=sum+10;}elseif(e.getSource()==button4){text.append("一雙襪子、");sum=sum+8;}elseif(e.getSource()==button5){text.append("\n"+"總價(jià)為:"+"\n"+sum);}}}publicclassShopping{publicstaticvoidmain(String[]args){newShopFrame("購(gòu)物車");}}我沒(méi)用Swing可能顯示不出來(lái)你的效果。不滿意得話我在給你編一個(gè)。
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("圓的周長(zhǎng)為:" + cir1.perimeter());
? Cylinder cy1 = new Cylinder(10, 15);
? System.out.println("圓柱體的表面積為:" + cy1.area());
? System.out.println("圓柱體的體積為:" + cy1.volume());
}
}
上面是我寫(xiě)的代碼,下圖是執(zhí)行結(jié)果,麻煩看一下,是否可以。
當(dāng)前名稱:java課堂實(shí)訓(xùn)代碼,Java程序設(shè)計(jì)實(shí)訓(xùn)
網(wǎng)站地址:http://chinadenli.net/article46/dsioceg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、電子商務(wù)、商城網(wǎng)站、網(wǎng)站策劃、動(dòng)態(tài)網(wǎng)站、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)