1 Star 0 Fork 0

mjfmcc/java_base

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
git add java_base 16.40 KB
一键复制 编辑 原始数据 按行查看 历史
mjfmcc 提交于 2024-07-26 18:51 . 代码好多写不出来
warning: in the working copy of 'array_src/practices_ary/ForOrderProcessingSystem.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'array_src/practices_ary/ForSalesDataAnalysis.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'array_src/practices_ary/ForStudentGradeProcessor.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'array_src/practices_ary/ForUserAgeAnalysis.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'oop/project/banks/README', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'while_and_if/practices_while/ControlGameScoreSystem.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'while_and_if/practices_while/ControlInventoryCheck.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'while_and_if/practices_while/ControlPaginationSystem.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'while_and_if/practices_while/ControlUserRegistrationSystem.java', LF will be replaced by CRLF the next time Git touches it
diff --git a/array_src/practices_ary/ForOrderProcessingSystem.java b/array_src/practices_ary/ForOrderProcessingSystem.java
index 27c0f02..d250397 100644
--- a/array_src/practices_ary/ForOrderProcessingSystem.java
+++ b/array_src/practices_ary/ForOrderProcessingSystem.java
@@ -17,9 +17,19 @@ public class ForOrderProcessingSystem {
double totalAmount = calculateTotal(orders);
System.out.println("订单的总金额: $" + totalAmount);

- // 查找订单金额大于某个阈值的订单,并返回这些订单的索引
+ // 查找订单金额最接近 /某个阈值的订单,并返回这些订单的索引
int idx = findOrdersAboveThreshold(orders, threshold);
System.out.println("最接近阈值 $" + threshold + "的索引 " + idx);
+ }
+ public static void calculateTotal(double[] orders){
+ double total = 0.0;
+ for (double order : orders){
+ total += order;
+ }
+ return total;
+ }
+ public static int findOrdersAboveThreshold(double[] orders,double[] threshold){
+
}
// 补充calculateTotalfindOrdersAboveThreshold方法定义以及实现
}
diff --git a/array_src/practices_ary/ForSalesDataAnalysis.java b/array_src/practices_ary/ForSalesDataAnalysis.java
index 2dbb0bf..1a49f02 100644
--- a/array_src/practices_ary/ForSalesDataAnalysis.java
+++ b/array_src/practices_ary/ForSalesDataAnalysis.java
@@ -1,15 +1,15 @@
package practices_ary;

-/**
- * 2. 销售数据分析
- *
- * 需求: 实现一个销售数据分析系统。给定一个数组,其中每个元素表示一个月的销售额。计算以下内容:
- *
- * 总销售额
- * 平均销售额
- * 销售额最高的月份
- * 销售额最低的月份
- * */
+///**
+// * 2. 销售数据分析
+// *
+// * 需求: 实现一个销售数据分析系统。给定一个数组,其中每个元素表示一个月的销售额。计算以下内容:
+// *
+// * 总销售额
+// * 平均销售额
+// * 销售额最高的月份
+// * 销售额最低的月份
+// * */
public class ForSalesDataAnalysis {
public static void main(String[] args) {
double[] sales = {1200.50, 1500.75, 1300.00, 1100.25, 1700.80, 1600.90, 1400.60, 1550.50, 1650.00, 1800.70, 1900.80, 2000.00};
@@ -27,5 +27,39 @@ public class ForSalesDataAnalysis {
System.out.println("Highest Sales Month: " + months[maxIndex] + " ($" + sales[maxIndex] + ")");
System.out.println("Lowest Sales Month: " + months[minIndex] + " ($" + sales[minIndex] + ")");
}
+
+ public static double calculateTotal(double[] sales){
+ double total = 0.0;
+ for (double sale : sales){
+ total += sale;
+ }
+ return total;
+ }
+
+ public static double calculateAverage(double[] sales){
+ double total = calculateTotal(sales);
+ total = total / sales.length;
+ return total;
+ }
+
+ public static int findMaxIndex(double[] sales){
+ int maxIndex = 0;
+ for (int i = 1; i < sales.length;i++){
+ if (sales[i] > sales[maxIndex]){
+ sales[maxIndex] = sales[i];
+ }
+ }
+ return maxIndex;
+ }
+
+ public static int findMinIndex(double[] sales){
+ int minIndex = 0;
+ for (int i = 1; i < sales.length;i++){
+ if (sales[i] < sales[minIndex]){
+ sales[minIndex] = sales[i];
+ }
+ }
+ return minIndex;
+ }
// 补充以上calculateTotalcalculateAveragefindMaxIndexfindMinIndex方法定义以及实现
}
diff --git a/array_src/practices_ary/ForStudentGradeProcessor.java b/array_src/practices_ary/ForStudentGradeProcessor.java
index c5780de..8dd642b 100644
--- a/array_src/practices_ary/ForStudentGradeProcessor.java
+++ b/array_src/practices_ary/ForStudentGradeProcessor.java
@@ -26,5 +26,39 @@ public class ForStudentGradeProcessor {
System.out.println("Highest Grade: " + grades[maxIndex] + " (Student Index: " + maxIndex + ")");
System.out.println("Lowest Grade: " + grades[minIndex] + " (Student Index: " + minIndex + ")");
}
+
+ public static int calculateTotal(int[] grades){
+ int total = 0;
+ for (int grade : grades){
+ total += grade;
+ }
+ return total;
+ }
+
+ public static int calculateAverage(int[] grades){
+ int total = calculateAverage(grades);
+ total = total / grades.length;
+ return total;
+ }
+
+ public static int findMaxIndex(int[] grades){
+ int maxIndex = 0;
+ for (int i = 1; i < grades.length;i++){
+ if (grades[i] > grades[maxIndex]){
+ grades[maxIndex] = grades[i];
+ }
+ }
+ return maxIndex;
+ }
+
+ public static int findMinIndex(int[] grades){
+ int minIndex = 0;
+ for (int i = 1; i < grades.length;i++){
+ if (grades[i] < grades[minIndex]){
+ grades[minIndex] = grades[i];
+ }
+ }
+ return minIndex;
+ }
// 补充calculateTotalcalculateAveragefindMaxIndexfindMinIndex的方法定义以及实现
}
diff --git a/array_src/practices_ary/ForUserAgeAnalysis.java b/array_src/practices_ary/ForUserAgeAnalysis.java
index 1bf7613..94da1d0 100644
--- a/array_src/practices_ary/ForUserAgeAnalysis.java
+++ b/array_src/practices_ary/ForUserAgeAnalysis.java
@@ -26,5 +26,44 @@ public class ForUserAgeAnalysis {
int countInRange = countInRange(ages, 20, 30);
System.out.println("年龄在20 ~ 30之间的总共: " + countInRange);
}
+
+ public static double calculateAverage(int[] ages){
+ int sum = 0;
+ for (int age : ages){
+ sum += age;
+ }
+ sum = sum / ages.length;
+ return sum;
+ }
+
+ public static int findMax(int[] ages){
+ int max = ages[0];
+ for (int age : ages){
+ if (age > max){
+ max = age;
+ }
+ }
+ return max;
+ }
+
+ public static int findMin(int[] ages){
+ int min = ages[0];
+ for (int age : ages){
+ if (age < min){
+ min = age;
+ }
+ }
+ return min;
+ }
+
+ public static int countInRange(int[] ages , int a,int b){
+ int total = 0;
+ for (int age : ages){
+ if (age >= a && age <= b){
+ total++;
+ }
+ }
+ return total;
+ }
// 补充 calculateAveragefindMaxfindMincountInRange方法定义以及实现
}
diff --git a/oop/project/banks/README b/oop/project/banks/README
index 2dd3ca8..a05fed0 100644
--- a/oop/project/banks/README
+++ b/oop/project/banks/README
@@ -1,6 +1,7 @@
2. 设计一个在线银行系统

-需求: 设计一个在线银行系统,包括账户和交易。账户类应包含账户的基本信息(如账户号码、账户余额)。交易类应记录每笔交易的详细信息(如交易金额、交易类型和交易日期)。系统应能够处理存款、取款和转账操作。
+需求: 设计一个在线银行系统,包括账户和交易。账户类应包含账户的基本信息(如账户号码、账户余额)。
+交易类应记录每笔交易的详细信息(如交易金额、交易类型和交易日期)。系统应能够处理存款、取款和转账操作。

提示:

diff --git a/while_and_if/practices_while/ControlGameScoreSystem.java b/while_and_if/practices_while/ControlGameScoreSystem.java
index 1603d2b..3fe38bd 100644
--- a/while_and_if/practices_while/ControlGameScoreSystem.java
+++ b/while_and_if/practices_while/ControlGameScoreSystem.java
@@ -1,5 +1,7 @@
package practices_while;

+import java.util.Scanner;
+
/**
*
* 游戏得分系统
@@ -13,4 +15,33 @@ package practices_while;
* 使用 break 来结束循环并计算总分和平均分。
* */
public class ControlGameScoreSystem {
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ int totalScore = 0;
+ int scoreCount = 0;
+
+ while(true){
+ System.out.println("请输入得分");
+ int score = scanner.nextInt();
+
+ if (score < 0){
+ break;
+ }
+ if (score == 0){
+ System.out.println("无效输入");
+
+ continue;
+ }
+
+ totalScore += score;
+ scoreCount++;
+ }
+
+ if (scoreCount > 0){
+ double a = totalScore / scoreCount;
+ System.out.println("总分:" + totalScore);
+ System.out.println("平均分:" + a);
+ }
+ scanner.close();
+ }
}
diff --git a/while_and_if/practices_while/ControlInventoryCheck.java b/while_and_if/practices_while/ControlInventoryCheck.java
index 03e4d21..317415a 100644
--- a/while_and_if/practices_while/ControlInventoryCheck.java
+++ b/while_and_if/practices_while/ControlInventoryCheck.java
@@ -1,5 +1,6 @@
package practices_while;

+import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.Scanner;

/**
@@ -23,7 +24,20 @@ public class ControlInventoryCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true){
+ System.out.println("用户输入购买的数量");
+ int control = scanner.nextInt();
+ if (INVENTORY < 0){
+ continue;
+ }
+ if (INVENTORY > 50){
+ System.out.println("库存不足,当前库存为:" + INVENTORY);
+ continue;
+ }
+
+ System.out.println("库存足够,可以购买,购买数量为:" + control);
+ break;
// 补充逻辑
}
+ scanner.close();
}
}
diff --git a/while_and_if/practices_while/ControlPaginationSystem.java b/while_and_if/practices_while/ControlPaginationSystem.java
index 8489a77..26784af 100644
--- a/while_and_if/practices_while/ControlPaginationSystem.java
+++ b/while_and_if/practices_while/ControlPaginationSystem.java
@@ -18,8 +18,22 @@ public class ControlPaginationSystem {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
+ int number = 0;
+ int pageNumber = 0;
+ int totalNumber = 50;
while(true){
System.out.print("Enter records per page (1-50): ");
+ number = scanner.nextInt();
+ if (number < 1 || number > 50){
+ System.out.println("无效输入");
+ continue;
+ }
+ int maxPageNumber = (totalNumber + number - 1) / number;
+ pageNumber = scanner.nextInt();
+ if (pageNumber < 1 || pageNumber > maxPageNumber){
+ System.out.println("无效输入,请重新输入");
+ continue;
+ }
// 补充逻辑
}
}
diff --git a/while_and_if/practices_while/ControlUserRegistrationSystem.java b/while_and_if/practices_while/ControlUserRegistrationSystem.java
index f3789a7..19b73ec 100644
--- a/while_and_if/practices_while/ControlUserRegistrationSystem.java
+++ b/while_and_if/practices_while/ControlUserRegistrationSystem.java
@@ -18,6 +18,12 @@ import java.util.Scanner;
public class ControlUserRegistrationSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
+ String username ;
+ String password ;
+ while (true){
+ System.out.println("请输入用户名(3-15个字符,只能包含字母):");
+ username = scanner.nextInt();
+ }
// 补充代码
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/mjfmcc/java_base.git
git@gitee.com:mjfmcc/java_base.git
mjfmcc
java_base
java_base
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385