2016-10-01 10 views
-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); 

    } 
} 
+0

あなたは情報を取得しようとしましたか、まさにどのような方法ですか? –

+0

最初の方法は、学生の名前を聞くために使用する必要があります、2番目の方法は、学生が何クレジットを取っているか尋ねる必要があります、そして3番目は授業料を計算することです。私は私の教授に電子メールを送ってきました(連絡する方が好ましい方法)、私のクラスのディスカッション掲示板に投稿しました。私は必死だ、今夜が来るからだ。 –

答えて

0

displayResultsは結果を表示するために使用される方法であり、あなたのコードを修正し、コードの以下の部分を見てみましょう。 calculateFeesは、計算に使用されるもう1つの方法です。残りの部分は、つまりあなたの要件がどのようにあなたに依存していますか?私はあなたにこのように他のものを実装することができるサンプルコードを与えました。

// Create constants. 
public static final double PER_CREDIT = 302.00; 

public static void main(String[] args) throws IOException { 
    // Create variables and objects. 
    int credTaken; 
    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(); 
    displayResults(credTaken,fullName); 

} 

static void displayResults(int credTaken, String fullName) { 
    // 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(); 
    } 
    double cost = calculateFees(credTaken); 
    // 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); 

} 

static double calculateFees(int credTaken) { 
    // Calculate the tuition cost. 
    return (credTaken * PER_CREDIT); 
} 
+0

ありがとうございました....私は私の現在の割り当てのための良い参考資料としてこれを使用できることを願っています。 –

関連する問題