-2
在我的java任務中,我創建了一個程序來執行應該發生的事情,但是我的教授的反饋是:此程序的主要任務是讓您學習創建方法;但是,您並未在程序中創建任何方法。我該如何添加方法?在java中添加方法(jGrasp)
/* Daniel Martos
This program will make use of methods with parameters and return values,
the scanner class, string methods, and nested for Loops. It will ask the
user for their full name and the number of credits that they are taking.
It will then calculate the cost of their tuition and print out the user's
full name, and tuition cost.
*/
// Import the java.util package in order to work with the scanner class.
import java.util.*;
public class Martos3 {
// Create constants.
public static final double PER_CREDIT = 302.00;
public static void main (String [] args) {
// Create variables and objects.
int credTaken;
double cost;
String fullName;
// Create the console object to allow us to read information in from the keyboard.
Scanner console = new Scanner (System.in);
// Create executable code.
System.out.println ("Welcome to the Cal U Tuition Calculator Program");
System.out.print ("Please enter your full name: ");
fullName = console.nextLine();
System.out.print ("Please enter the number of credits taken: ");
credTaken = console.nextInt();
// Add a Nested for Loop to add the dashes
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 50; j++) {
System.out.print ("-");
}
System.out.println();
}
// Calculate the tuition cost.
cost = (credTaken * PER_CREDIT);
// Print out "Tuition calucation for" and the user's full name followed by a .
System.out.println ("Tuition calulation for " + fullName + ".");
// Print out "Credits Taken =" with the number of credits that the user enters.
System.out.println ("Credits Taken = " + credTaken);
// Print out "Tuition Cost = $" and the cost of tutition calculation.
System.out.println ("Tuition Cost = $" + cost);
}
}
您是否試圖獲取信息,究竟是什麼方法? –
第一種方法應該用於詢問學生的姓名,第二種方法應該是詢問學生有多少學分,第三種方法是計算學費。我通過電子郵件發送了我的教授(首選聯繫方式)併發布到我的課堂討論版上,我沒有收到任何反饋。我很絕望,因爲今晚會到期。 –