本文目錄一覽:
- 1、java作業題,都在這裡了,希望你幫忙解答下
- 2、java編程題目,求求大佬救救我
- 3、JAVA編程題求解?
- 4、求解兩道JAVA作業題!懸賞50,在線等!~
- 5、java編程題 希望大家能夠幫助我一下,謝謝?
- 6、java編程題 本人新手,求詳解。
java作業題,都在這裡了,希望你幫忙解答下
1選擇題
1,B
2.D
3.D
2.int i = 30;
double d[] = new double[30];
char[] r = new char[30];
int[] i = {3,4,5,6};
float f[] ={2.3F,3.5F,6.6F};
char[] c = new char[3];
3. int類型,最小為0,a[2]
4. double[] d = new double[10];
d[9] = 5.5D;
double result = d[0] + d[1];
5. public static void method1(int n, int m) {
n += m;
method2((int) 3.4);
}
public static int method2(int n) {
if (n 0)
return 1;
else if (n == 0)
return 0;
else
return -1;
}
6.
public double getPromotion(double amount, double percent)
public void print(int year, int month)
public double sqrt(double d)
public boolean isOdd(int i);
public void printMsg(int times);
public double getLoanMonthlyPayment(double totalMoney, int loanYears, double interest);
public Char toUpperCase(char c);
public static void question1() {
Scanner scanner = new Scanner(System.in);
double[] scores = new double[10];
int i = 0;
double totalScore = 0;
while (i 10) {
double d = scanner.nextDouble();
scores[i] = d;
i++;
totalScore += d;
}
double avgScore = totalScore / 10;
Arrays.sort(scores);
int index = Arrays.binarySearch(scores, avgScore);
System.out.println(“低於平均成績的” + (index));
System.out.println(“高於平局成績的” + (10 – index));
scanner.close();
}
public static void question2() {
double[] scores = { 10.0, 9.0, 8.0, 10.0, 7.0, 10.0, 9.0, 8.0, 10.0, 7.0 };
Arrays.sort(scores);
double[] newScores = new double[8];
for (int i = 1; i scores.length – 2; i++) {
newScores[i – 1] = scores[i];
}
double totalScore = 0;
for (int i = 0; i newScores.length; i++) {
totalScore += newScores[i];
}
System.out.println(“得分是” + totalScore);
}
public static void question3() {
double[] d = new double[] { 1, 2, 3, 4, 5 };
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
for (int i = 0; i d.length; i++) {
if (min d[i]) {
min = d[i];
}
if (max d[i]) {
max = d[i];
}
}
System.out.println(“最大值” + max);
System.out.println(“最小值” + min);
}
public static int average(int[] array) {
int total = 0;
for (int i = 0; i array.length; i++) {
total += array[i];
}
return total / array.length;
}
public static double average(double[] array) {
double total = 0;
for (int i = 0; i array.length; i++) {
total += array[i];
}
return total / array.length;
}
public boolean equals(int[] list1, int[] list2) {
if (list1 == null) {
return false;
}
if (list2 == null) {
return false;
}
if (list1.length != list2.length) {
return false;
}
for (int i = 0; i list1.length; i++) {
if (list1[i] != list2[i]) {
return false;
}
}
return true;
}
java編程題目,求求大佬救救我
這個題考察的是面向對象三大特性之一的繼承。
子類繼承父類。
項目結構如何所示:
Mobile 為父類,有一個屬性:mobilePhone 代表電話號碼。
有4個方法(功能):
1、獲取手機號碼:public String getMobilePhone(){}
2、存儲手機號碼:public void setMobilePhone(String mobilePhone) {}
3、撥打電話號碼:public void callOnMobilePhone(){}
4、掛斷電話:public void callOffPhone(){}
具體代碼如下所示:、
————————————–mobilePhone 開始————————————–
/**
* @author 馮修遠
* 創建一個第一代手機類,要求包含手機號碼信息,並包含獲取電話號碼,
* 存儲電話號碼、撥打電話號碼和掛斷電話等功能。並以此為父類,派生
* 出子類第二代手機類,增加拍照功能。以第二代手機類來生成對象並
* 模擬實現撥打電話、掛斷電話拍照等功能。
*/
public class Mobile {
//手機號碼
private String mobilePhone;
/**
* 獲取手機號碼
* @return
*/
public String getMobilePhone() {
return mobilePhone;
}
/**
* 存儲手機號碼
* @param mobilePhone
*/
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
/**
* 撥打電話號碼
*/
public void callOnMobilePhone(){
System.out.println(“撥打電話號碼:”+mobilePhone);
}
/**
* 掛斷電話
*/
public void callOffPhone(){
System.out.println(“掛斷與:”+mobilePhone+”的通話”);
}
}
————————————–mobilePhone 結束————————————–
PhotoMobile 為子類或者叫派生類,繼承自父類:Mobile
同時也繼承了父類的4個方法,但父類的屬性因為我設置的是private,所以繼承不了。
PhotoMobile 的代碼如下圖所示:
最後一個類,也就是測試類,用於創建第二代手機的對象,並調用相應的功能,如下圖所示:
最終,程序的運行結果如下圖所示:
我是馮修遠,如果我的答案對您有幫助的話,請採納以幫助更多的人,如果還有其它的問題,也請關注我,私信我,謝謝!
JAVA編程題求解?
這種作業,最好還是結合書上知識,理解清楚老師布置的目的、怎麼實現的
public class Frog {
private String name;
private Integer distance = 0;
//跳躍方法
void jump() {
//隨機10-20
int jumpDistance = (int) (10 + Math.random() * (20 – 10 + 1));
this.distance += jumpDistance;
}
//帶名字構造方法
Frog(String name) {
this.name = name;
}
public static void main(String[] args) {
Frog a = new Frog(“a”);
Frog b = new Frog(“b”);
Frog c = new Frog(“c”);
Frog d = new Frog(“d”);
for (int i = 0; i 10; i++) {
a.jump();
b.jump();
c.jump();
d.jump();
}
System.out.println(a.name + “總距離=” + a.distance);
System.out.println(b.name + “總距離=” + b.distance);
System.out.println(c.name + “總距離=” + c.distance);
System.out.println(d.name + “總距離=” + d.distance);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getDistance() {
return distance;
}
public void setDistance(Integer distance) {
this.distance = distance;
}
}
求解兩道JAVA作業題!懸賞50,在線等!~
第一題:
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ex3_1 {
/**
* @param args
*/
public static void main(String[] args) {
char c;
int i=0;
String s=”The past is gone and static. Nothing we can do willchange it. ” +
“Thefuture is before us and dynamic. Everything we do will affect it.”;
System.out.println(“請輸入一個字母”);
Scanner sc = new Scanner(System.in);
c=sc.next().charAt(0);//輸入單個字符
Pattern p=Pattern.compile(String.valueOf(c));
Matcher m=p.matcher(s);
while(m.find()){
i++;
}
System.out.println(“指定字符”+c+”出現的頻率為”+i);
}
}
第二題:
import java.util.Arrays;
public class Ex3_2 {
public static void main(String[] args) {
int[] a = new int[20];
int b=0;
int max=0;
for(int i=0;ia.length;i++){
a[i]=(int) (Math.random()*99);
}
System.out.println(Arrays.toString(a));
for(int j=0;ja.length;j++){
for(int k=0;kj;k++){
if(a[j]a[k]){
a[k]=a[j];
a[k]=b;
b=a[j];
}
}
}
max=a[0];
Arrays.sort(a);
System.out.println(max);
}
}
java編程題 希望大家能夠幫助我一下,謝謝?
package book;
/**
* @Author: Cool_Wu
* @Date: 2020-12-07 20:18
*/
public class Book {
private String name;
private String num;
private String author;
private double price;
private String publishing_House;
private String publication_Date;
public Book() {}
public Book(String name, String num, String author, double price, String publishing_House, String publication_Date) {
this.name = name;
this.num = num;
this.author = author;
this.price = price;
this.publishing_House = publishing_House;
this.publication_Date = publication_Date;
}
@Override
public String toString() {
return “圖書信息:\n———————-” +
“\n書名:” + name +
“\n書號:” + num +
“\n作者:” + author +
“\n單價:” + price +
“\n出版社:” + publishing_House +
“\n出版日期:” + publication_Date +
“\n———————-\n”;
}
}
package book;
public class Test {
public static void main(String[] args) {
Book book1 = new Book(“百年孤獨”,”10000″,”加西亞·馬爾克斯”,40.00,”南海出版公司”,”2017年08月”);
System.out.println(book1);
Book book2 = new Book(“時間簡史”,”10086″,”史蒂芬·霍金”,22.50,”湖南科技出版社”,”2014年06月”);
System.out.println(book2);
}
}
運行結果
java編程題 本人新手,求詳解。
先看下最終的結果吧,是不是你想要的?
項目結構如下圖所示:
其中,Student是父類,PostGraduate是子類,繼承自父類Student,Main是主類,用於創建對象以及把這些對象的功能調用起來。
—————————Student代碼如下:——————————
/**
* 學生類
* @author 逍遙
*
*/
public class Student {
//學號
private int sId;
//姓名
private String sName;
//數學成績
private double mathScore;
//計算機成績
private double computerScore;
/**
* 獲取學號
* @return
*/
public int getsId() {
return sId;
}
/**
* 設置學號
* @param sId
*/
public void setsId(int sId) {
this.sId = sId;
}
/**
* 獲取姓名
* @return
*/
public String getsName() {
return sName;
}
/**
* 設置姓名
* @param sName
*/
public void setsName(String sName) {
this.sName = sName;
}
/**
* 獲取數學成績
* @return
*/
public double getMathScore() {
return mathScore;
}
/**
* 設置數學成績
* @param mathScore
*/
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
}
/**
* 獲取計算機成績
* @return
*/
public double getComputerScore() {
return computerScore;
}
/**
* 設置計算機成績
* @param computerScore
*/
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
}
/**
* 輸出成員變量(4個成員變量)的信息。
*/
public void print(){
System.out.println(“學號:”+sId);
System.out.println(“姓名:”+sName);
System.out.println(“計算機成績:”+mathScore);
System.out.println(“數學成績:”+computerScore);
}
}
—————————Student代碼結束——————————
—————————PostGraduate代碼如下:——————————
/**
* 研究生類
* @author 逍遙
*
*/
public class PostGraduate extends Student{
//導師姓名
private String tName;
//研究方向
private String ResearchDirection;
/**
* 獲取導師姓名
* @return
*/
public String gettName() {
return tName;
}
/**
* 設置導師姓名
* @param tName
*/
public void settName(String tName) {
this.tName = tName;
}
/**
* 獲取研究方向
* @return
*/
public String getResearchDirection() {
return ResearchDirection;
}
/**
* 設置研究方向
* @param researchDirection
*/
public void setResearchDirection(String researchDirection) {
ResearchDirection = researchDirection;
}
/**
* 研究生類重寫父類的void print()方法,功能是輸出成員變量(6個成員變量)的信息
*/
@Override
public void print() {
// TODO Auto-generated method stub
super.print();
System.out.println(“導師姓名:”+tName);
System.out.println(“研究方向:”+ResearchDirection);
}
}
—————————PostGraduate代碼結束——————————
—————————Main代碼如下:——————————
import java.util.Scanner;
/**
* 主類
* @author 逍遙
*
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//用於獲取從鍵盤上輸入的信息
Scanner input=new Scanner(System.in);
//創建一個Student類的對象
Student student=new Student();
//從鍵盤上輸入其屬性信息
System.out.print(“請輸入學生的學號:”);
student.setsId(input.nextInt());
System.out.print(“請輸入學生的姓名:”);
student.setsName(input.next());
System.out.print(“請輸入學生的數學成績:”);
student.setMathScore(input.nextDouble());
System.out.print(“請輸入學生的計算機成績:”);
student.setComputerScore(input.nextDouble());
//並且通過其print方法輸出這些信息;
student.print();
//創建一個PostGraduate類的對象
PostGraduate postGraduate=new PostGraduate();
//從鍵盤上輸入其屬性信息
System.out.print(“請輸入研究生的學號:”);
postGraduate.setsId(input.nextInt());
System.out.print(“請輸入研究生的姓名:”);
postGraduate.setsName(input.next());
System.out.print(“請輸入研究生的數學成績:”);
postGraduate.setMathScore(input.nextDouble());
System.out.print(“請輸入研究生的計算機成績:”);
postGraduate.setComputerScore(input.nextDouble());
System.out.print(“請輸入研究生的導師姓名:”);
postGraduate.settName(input.next());
System.out.print(“請輸入研究生的研究方向:”);
postGraduate.setResearchDirection(input.next());
//並且通過其print方法輸出這些信息。
postGraduate.print();
}
}
—————————Main代碼結束——————————
=================知識點的簡單總結=================
本題考察的知識點是面向對象的三大特性之一:繼承。
Student為父類,包含了學號、姓名、數學成績和計算機成績4個屬性,以及一個print()方法。
PostGraduate 繼承父類的時候,繼承了父類中的所有方法,因為方法我都是用的public,而屬性繼承不了,因為我在父類中用了封裝,所有屬性都用private修飾了,想訪問屬性的話,必須通過get、set方法,這裡,我重寫了父類中的print方法,通過super.print();調用了父類中的print()方法。
最後就是Main類,提供了main方法作為入口函數,用於按要求聲明這些對象以及去調用對象中的方法。
原創文章,作者:WKRZ,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/132671.html