public class Test {
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、网页空间、营销软件、网站建设、洮南网站维护、网站推广。
public static void main(String[] args) {
MyRectangle rec = new MyRectangle(3, 5);
MyRectangle square = new MySquare(4);
System.out.println(rec.toString());
System.out.println(square.toString());
}
}
class MyRectangle{
protected double width;
protected double length;
public MyRectangle(double length, double width){
this.width = width;
this.length = length;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getArea(){
return this.width * this.length;
}
public String toString(){
return "长方形的长为:" + length + ", 宽: " + width + ", 面积为:" + getArea();
}
}
class MySquare extends MyRectangle{
public MySquare(double length){
super(length, length);
}
public double getArea(){
return Math.pow(super.width, 2);
}
public String toString(){
return "正方形边长为: " + super.length + ", 面积为: " + getArea();
}
}
----------测试
长方形的长为:3.0, 宽: 5.0, 面积为:15.0
正方形边长为: 4.0, 面积为: 16.0
1.确保写的类没问题,java程序是先编译,后执行
2.打开cmd,进入该文件所在路径,输入javac -d 类名.java,对该java源文件编译,生成class文件
3.再输入java 类名 ,就可以运行这个程序了。
如果有多个类,需要写个bat批处理文件,即同时运行多个java类、jar包、配置文件、资源文件。
import java.util.Scanner;
/*输入一个成绩,将该成绩转换为A、B、C、D和E:成绩在90分以上,结果为A,成绩在80-90之间,结果为B,成绩在70-80之间,结果为C,成绩在60-70之间,结果为D,成绩在60分以下,结果为E。*/
public class Chengfabiao
{
public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
if(score90)
{
System.out.println("A");
}
else if(score=80)
{
System.out.println("B");
}
else if(score=70)
{
System.out.println("C");
}
else if(score=60)
{
System.out.println("D");
}
else
{
System.out.println("E");
}
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class LoginFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 2899557721654693611L;
final JTextField jt1 = new JTextField ();
final JTextField jt2 = new JTextField ();
public LoginFrame() {
this.setTitle("学生登陆");
this.setLayout(null);
this.setBounds(200, 200, 400, 300);
JButton jb1 = new JButton("登陆");
JButton jb2 = new JButton("退出");
jb1.setBounds(50, 230, 80, 20);
jb2.setBounds(270,230,80,20);
jt1.setBounds(170,80,100,20);
jt2.setBounds(170,170,100,20);
JLabel jl1 = new JLabel("用户名");
JLabel jl2 = new JLabel("密码");
jl1.setBounds(80, 80, 50, 20);
jl2.setBounds(80, 170, 50, 20);
add(jb1);
add(jb2);
add(jt1);
add(jt2);
add(jl1);
add(jl2);
this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
setVisible(false);
System.exit(0);
}
});
jb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new IntoTxt().intotex(jt1.getText(), jt2.getText());
}
});
jb2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
setVisible(false);
System.exit(0);
}
});
}
public static void main(String[] args) {
LoginFrame lf = new LoginFrame();
}
}
class IntoTxt {
public void intotex(String name,String password) {
BufferedWriter bw;
File file = new File("D:/write.txt");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
bw = new BufferedWriter(new FileWriter(file,true));
bw.newLine();
bw.write("用户名是 ");
bw.write(name);
bw.write(" 密码是 ");
bw.write(password);
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
eclipse显示被隐藏的文件或文件夹
点击左边导航(Navigator或者PackageExplorer等)右上角的小三角 - Filters
点击需要显示文件,让复选框处于非选中状态。