本文目錄一覽:
- 1、西安電子科技大學java期末有上機考試嗎?
- 2、救急啊!!!期末考試!怎樣用JAVA的GUI(圖形用戶界面)來設計一個小程序!
- 3、java期末考試!!求助!!!
- 4、大學java期末考試求求大家幫忙
- 5、從鍵盤輸入期末考試成績,求最高分、最低分、總分和平均分,並將成績從高到低列印出來。 Java!求大神
- 6、高分求做簡單JAVA期末考試
西安電子科技大學java期末有上機考試嗎?
有上機考試。可以提前搜索了解歷年的考試題目進行練習上機操作,根據導師上課的重點要求多複習。
救急啊!!!期末考試!怎樣用JAVA的GUI(圖形用戶界面)來設計一個小程序!
給你找了一個,我試過,可以用
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.*;//GUi之前要吧這兩個都引進來
public class Computer extends JFrame implements ActionListener
{
JButton a1,a2,a3,a4,a5,a6,a7,a8,a9,a0;
JButton b1,b2,b3,b4;
JButton c1,c2,c3,c4;
JTextField t1,t2;
JPanel p1,p2;
JLabel bq1,bq2;
String fuhao;
Double count,count2;
boolean chose=false,cliks;
public static void main(String[] args){
Computer l = new Computer();
}
public Computer(){
Font font = new Font(“宋體”, Font.BOLD, 36);
Font font2 = new Font(“宋體”, Font.BOLD, 20);
a1 = new JButton(“1”);
a1.setFont(font);
a1.addActionListener(this);
a2 = new JButton(“2”);
a2.setFont(font);
a2.addActionListener(this);
a3 = new JButton(“3”);
a3.setFont(font);
a3.addActionListener(this);
a4 = new JButton(“4”);
a4.setFont(font);
a4.addActionListener(this);
a5 = new JButton(“5”);
a5.setFont(font);
a5.addActionListener(this);
a6 = new JButton(“6”);
a6.setFont(font);
a6.addActionListener(this);
a7 = new JButton(“7”);
a7.setFont(font);
a7.addActionListener(this);
a8 = new JButton(“8”);
a8.setFont(font);
a8.addActionListener(this);
a9 = new JButton(“9”);
a9.setFont(font);
a9.addActionListener(this);
a0 = new JButton(“0”);
a0.setFont(font);
a0.addActionListener(this);
b1 = new JButton(“清空”);
b1.addActionListener(this);
b2 = new JButton(“返回”);
b2.addActionListener(this);
b3 = new JButton(“.”);
b3.addActionListener(this);
b4 = new JButton(“=”);
b4.addActionListener(this);
c1 = new JButton(“+”);
c1.addActionListener(this);
c2 = new JButton(“-“);
c2.addActionListener(this);
c3 = new JButton(“x”);
c3.addActionListener(this);
c4 = new JButton(“÷”);
c4.addActionListener(this);
t1 = new JTextField(25);
t2 = new JTextField(35);
t1.setFont(font2);
t2.setFont(font2);
p1 = new JPanel();
p2 = new JPanel();
bq1 = new JLabel(“結”);
bq2 = new JLabel(“果”);
p1.setLayout(new GridLayout(2,3));
p2.setLayout(new GridLayout(4,4));
p1.add(t1);p1.add(b1);p1.add(b2);
p1.add(t2);p1.add(bq1);p1.add(bq2 );
p2.add(a1);p2.add(a2);p2.add(a3);p2.add(c1);
p2.add(a4);p2.add(a5);p2.add(a6);p2.add(c2);
p2.add(a7);p2.add(a8);p2.add(a9);p2.add(c3);
p2.add(b3);p2.add(a0);p2.add(b4);p2.add(c4);
this.add(p1,BorderLayout.NORTH);
this.add(p2,BorderLayout.CENTER);
this.setSize(460,380);
this.setTitle(“簡易計算器”);
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object temp = e.getSource();
if(temp == a1){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”1″);
chose=false;
}
if(temp == a2){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”2″);
chose=false;
}
if(temp == a3){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”3″);
chose=false;
}
if(temp == a4){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”4″);
chose=false;
}
if(temp == a5){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”5″);
chose=false;
}
if(temp == a6){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”6″);
chose=false;
}
if(temp == a7){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”7″);
chose=false;
}
if(temp == a8){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”8″);
chose=false;
}
if(temp == a9){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”9″);
chose=false;
}
if(temp == a0){
if(chose==true){t1.setText(“”);t2.setText(“”);}
t1.setText(t1.getText()+””+”0″);
chose=false;
}
if(temp==b3){
cliks=true;
for(int i=0;it1.getText().length();i++){
if(‘.’==t1.getText().charAt(i)){
cliks=false;
break;
}
if(cliks==true){
t1.setText(t1.getText()+”.”);
}
}
}
if(temp== c1){
count=Double.parseDouble(t1.getText());
t1.setText(“”);
fuhao = “+”;
}
if(temp== c2){
count=Double.parseDouble(t1.getText());
t1.setText(“”);
fuhao = “-“;
}
if(temp== c3){
count=Double.parseDouble(t1.getText());
t1.setText(“”);
fuhao = “*”;
}
if(temp== c4){
count=Double.parseDouble(t1.getText());
t1.setText(“”);
fuhao = “÷”;
}
if(temp==b1){
t1.setText(“”);
t2.setText(“”);
}
if(temp==b2){
String s=t1.getText();
t1.setText(“”);
for(int i=0;is.length()-1;i++){
char a = s.charAt(i);
t1.setText(t1.getText()+a);
}
}
if(temp== b4){
count2=Double.parseDouble(t1.getText());
t1.setText(“”);
if(fuhao==”+”){
//int sum=count+count2;
t1.setText(count+””+fuhao+””+count2+””+”=”);
t2.setText(count+count2+””);
chose=true;
}
if(fuhao==”-“){
//int sum=count+count2;
t1.setText(count+””+fuhao+””+count2+””+”=”);
t2.setText(count-count2+””);
chose=true;
}
if(fuhao==”*”){
//int sum=count+count2;
t1.setText(count+””+fuhao+””+count2+””+”=”);
t2.setText(count*count2+””);
chose=true;
}
if(fuhao==”÷”){
//int sum=count+count2;
if(count2==0){
t1.setText(count+””+fuhao+””+count2+””);
t2.setText(“除數不能為0”);
return;
}
t1.setText(count+””+fuhao+””+count2+””+”=”);
t2.setText(count/count2+””);
chose=true;
}
}
}
}
java期末考試!!求助!!!
1.
第一種:
當X=10時 X-1=X; 無效表達式
當X=10時 X-=3; 等價於 X=X-3; 運算後x的值:7
當X=10時 X*=1+2; 等價於 X=X*(1+2); 運算後x的值:30
當X=10時 X%=5; 等價於 X=X%5; 運算後x的值:0
第二種:
如果是問 X 經過後三個表達式運算後的值(第一個表達式是錯的):
X=X-3; 此時 X=7
X=X*(1+2); 此時 X=21
X=X%5; 此時 X=1
最後X為1
2.
當a=6; b=-4;時 –a%++b; 等價於 (a-1)%(b+1); 運算後的值:2
當a=6; b=-4;時 (–a)a;; 等價於 (a-1)a; 運算後的值:160
位運算
a-1的值為5
5的二進位為 101
55 表示把五的二進位向左移動5位 即101 00 000換十進位為160
當a=6; b=-4;時 (a10 a10 ? a:b); 等價於
如果a小於10 並且 a大於10 表達式的值為a也就是6 否則表達式的值為b 即-4
一個數不可能同時小於10又大於10 所以 表達式的值為b 也就是-4
大學java期末考試求求大家幫忙
%!
int a=20;
%
%a+=2;%
%a%
更多科目問題請追問
從鍵盤輸入期末考試成績,求最高分、最低分、總分和平均分,並將成績從高到低列印出來。 Java!求大神
package test;
import java.util.Arrays;
import java.util.Scanner;
public class Chengji {
public static void main(String[] args) {
int Math;
int Phi;
int Eng;
Scanner scan = new Scanner(System.in);
System.out.println(“[輸入你的數學成績]”);
Math = scan.nextInt();
System.out.println(“[請輸入你的物理成績]”);
Phi=scan.nextInt();
System.out.println(“[請輸入你的英語成績]”);
Eng=scan.nextInt();
int []arr={Math,Phi,Eng};
int max=getMax(arr);
int min=getMin(arr);
double sum=getSum(arr);
Arrays.sort(arr);
System.out.println(“最高分:”+max);
System.out.println(“最低分:”+min);
System.out.println(“平均分”+sum);
System.out.println(“大到小的成績為”+Arrays.toString(arr));
}
/**
* 取出數組中的最大值
* @param arr
* @return
*/
public static int getMax(int[] arr){
int max=arr[0];
for(int i=1;iarr.length;i++){
if(arr[i]max){
max=arr[i];
}
}
return max;
}
/**
* 取出數組中的最小值
* @param arr
* @return
*/
public static int getMin(int[] arr){
int min=arr[0];
for(int i=1;iarr.length;i++){
if(arr[i]min){
min=arr[i];
}
}
return min;
}
/**
* 取出數組中的平均值
* @param arr
* @return
*/
public static double getSum(int[] arr){
double temp = 0;
double sum = 0;
for(int i=1;iarr.length;i++){
sum=sum+arr[i];
}
temp=sum/arr.length;
return temp;
}
}
高分求做簡單JAVA期末考試
1. Application 創建一個類,然後寫一個主函數,再寫一些程序在主函數里就是一個簡單的Appliction
Applet 創建一個類繼承Applet類,然後實現init,start,destory方法,這個就可以了
2. Java介面,Java語言中存在的結構,有特定的語法和結構; 包就是一個文件夾
3. 多態包括重載和重構 最通俗的程序例子,昨天剛寫的
/**
簡單的通俗的講:
繼承就是兒子繼承了父親,一個類內有一個父親,但一個父親可以有多個兒子
多態就是兒子雖然繼承了父親的一些特性,但有些特性有了改變
封裝就是有些東西兒子是父親獨有的兒子繼承不了
*/
class FatherClass {
//FatherClass的成員變數
//父親公開的屬性兒子,孫子,侄子都能訪問 a
public int a;
//父親私有的屬性,兒子繼承不了,在子類中也不能訪問 b
private int b;
//FatherClass的成員方法
//父親公開的方法兒子,孫子,侄子都能訪問 eat
public void eat(){
System.out.println(“Father eat!”);
}
public void drink(){
System.out.println(“Father drinking!”);
}
//父親私有的方法,兒子繼承不了,在子類中也不能訪問 方法height
private void height(){
System.out.println(“Father height!”);
}
//父親的最終方法poor,也就是說兒子不能覆蓋這個方法(兒子不能有和父親方法頭一樣的函數)
public final void poor(){
System.out.println(“Father poor!”);
}
}
class SubClass extends FatherClass {
//雖繼承了父親的吃方法,但兒子又拓展了父親的吃方法,要帶餐具(多態中的一:重載)
public void eat(String tool){
System.out.println(tool+” :Son eat!”);
}
//和父親的喝方法一樣,不過這是兒子自己的喝方法,不是從父親那裡來的(多態中的二:覆蓋或重寫或重構)
public void drink(){
System.out.println(“Son drinking!”);
}
public static void print(){
System.out.println(“Static Function!”);
}
}
public class ExtendsTest {
public static void main(String[] args) {
SubClass sc=new SubClass();
sc.eat();//兒子繼承了父親的吃方法,可以直接使用
sc.eat(“Bowl”);//雖然兒子繼承了父親的吃方法,可是兒子也有自己的吃方法(拓展了),得用餐具吃
sc.drink();//這裡調用的是兒子的喝方法而不是父親的噢,父親的被兒子覆蓋了
//sc.height();//父親私有的兒子不能使用
SubClass.print();//靜態方法直接使用 類名.方法名 調用
}
}
5.
面向對象特徵:繼承,多態,封裝
6.
import java.util.Scanner;
public class CountNum {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print(“請輸入一個整數:”);
int number=sc.nextInt();
int sum=0;
for(int i=1;i=number;i++){
sum+=i;
}
System.out.println(“1+2+…+number=”+sum);
}
}
7.
public class Student {
private long id;
private String name;
private int age;
boolean sex;
String phone;
public Student(long i, String n, int a, boolean s, String p) {
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
int getage() {
return age;
}
boolean getsex() {
return sex;
}
Long getphone() {
return Long.parseLong(phone);
}
public String tostring() {
return name;
}
}
還不多呢
總算弄完了,,
呵呵…………
祝你好運哈。。。
原創文章,作者:JYYR,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/136889.html