2015-10-04 3 views
-3

Я пишу программу, которая должна отображать вывод, основанный на некоторых введенных числах. Я получаю вывод, и он полностью пуст, и ни один из расчеты выполняютсяПрограмма не отображает вывод правильно

/** 
* 
* @NMATA003PA1.java 
* @author Nicholas Mata 
* @version 1.00 2015/09/25 
* 
* Program Purpose: This program controls whether a customer can calculate the cost of his/her stock purchases. 
* 
*/ 

import java.util.Scanner; //Scanner is imported to capture user input 
import java.util.Calendar;//Calendare is imported to reflect the current date when necessary 

public class MataN003PA1 

{ 
    public static void main(String[] args)//Customer will be able to calculate costs of multiple trades 
    { 
     String customerName = "", date = "";//Customer name and date are declared as Strings 
     int shares = 0, noOfStocks = 0;//shares and noOfShares are declared as integers, they are set to zero 
     double sharePrice = 0, stockCost = 0, commission = 0, totalCost = 0, onlineFee = 0, totalStockCost = 0, totalCommissions = 0, totalOnlineFees = 0; 
     /** 
     * sharePrice, stockCost, commission, totalCost, onlineFee, totalStockCost, totalCommissions, totalOnline Fees are declared 
     * as double, they are also set to zero 
     */ 
     char onlineTrade = ' ', brokerAssisted = ' ', another = ' '; // onlineTrade and brokerAssisted are declared as char variables, set to blank 
     Calendar dateTime = Calendar.getInstance(); //dateTime is declared 

     Scanner input = new Scanner(System.in); 

     System.out.printf("%nYEE-TRADE, INC. - The Wild West of Electronic Trading" 
     +"%n%nWelcome to Yee-Trade's stock purchase calculator.%n"); 

     System.out.printf("%n%nWhat is your name? "); 
     customerName = input.nextLine(); 

     System.out.printf("%nDo you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: "); 
     another = input.nextLine().charAt(0); 

     while (Character.toUpperCase(another) == 'Y') 
     { 
      noOfStocks = noOfStocks + 1; 

      System.out.printf("%nHow many shares did you purchase? "); 
      shares = input.nextInt(); 

      System.out.printf("%nWhat is the price per share? "); 
      sharePrice = input.nextDouble(); 
      input.nextLine(); 

      stockCost = shares * sharePrice; 
      totalStockCost = totalStockCost + stockCost; 
      totalCost = totalCost + stockCost; 

      System.out.printf("%nIs this an online trade? Enter 'Y' or 'N': "); 
      onlineTrade = input.nextLine().charAt(0); 

      if (Character.toUpperCase(onlineTrade) == 'Y') 
      { 
       onlineFee = 5.95; 
       totalOnlineFees = totalOnlineFees + onlineFee; 
       totalCost = totalCost + onlineFee; 
      }//END if_1 
      else 
      { 
       System.out.printf("%nIs this a broker assisted trade? Enter 'Y' or 'N': "); 
       brokerAssisted = input.nextLine().charAt(0); 

       if (Character.toUpperCase(brokerAssisted) == 'Y') 
       { 
        commission = stockCost * .02; 
        totalCommissions = totalCommissions + commission; 
        totalCost = totalCost + commission; 

       }//END if_2 
       else 
       { 
        System.out.printf("%nINVALID TRADE TYPE! %n"); 
        noOfStocks = noOfStocks - 1; 
        totalStockCost = totalStockCost - stockCost; 
        totalCost = totalCost - stockCost; 
       }//end else_2 
      }//end else_1 

      System.out.printf("%nEnter 'Y' to calculate the cost of another stock purchase or 'N' to exit: "); 
      another = input.nextLine().charAt(0); 

     }//END WHILE LOOP 

     if (noOfStocks > 0); 
     { 
      System.out.printf("%nYEE-TRADE, INC." 
      +"%nTOTAL COST OF STOCK PURCHASES" 
      +"%nFOR %s", customerName); 
      System.out.printf("%nAS OF "); 
      System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime); 
      System.out.printf("%nTotal Stock Cost: $", totalStockCost); 
      System.out.printf("%nTotal Online Fees: $", totalOnlineFees); 
      System.out.printf("%nTotal Commissions: $", totalCommissions); 
      System.out.printf("%n%nTOTAL COST: $", totalCost); 

     }//END if_3 

     System.out.printf("%nThank you for using Yee-Trade's stock purchase calculator! "); 

     noOfStocks = 0; 



     System.exit(0);}//END MAIN 
}//END CLASS 
+0

есть ли exception – SSH

+0

Привет и добро пожаловать в StackOverflow, вы должны проверить эту страницу: http://stackoverflow.com/help/mcve –

+0

и что такое результат? – ergonaut

ответ

1

Вы не должны всегда пытаться format выход, если нет необходимости.

Вот ваша проблема:

 System.out.printf("%nAS OF "); 
     System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime); 
     System.out.printf("%nTotal Stock Cost: $" + totalStockCost); 
     System.out.printf("%nTotal Online Fees: $", totalOnlineFees); 
     System.out.printf("%nTotal Commissions: $", totalCommissions); 
     System.out.printf("%n%nTOTAL COST: $", totalCost); 

Вы должны будете заменить большинство из них с последующим

 System.out.printf("%nAS OF "); 
     System.out.printf("%1$TB %1$Td, %1$TY%n", dateTime); 
     System.out.println("Total Stock Cost: $" + totalStockCost); 
     System.out.println("Total Online Fees: $" + totalOnlineFees); 
     System.out.println("Total Commissions: $" + totalCommissions); 
     System.out.println("TOTAL COST: $" + totalCost); 

Вот результат я получаю:

YEE-TRADE, INC. - The Wild West of Electronic Trading 

    Welcome to Yee-Trade's stock purchase calculator. 


    What is your name? Yassin 

    Do you want to calculate your stock purchases? Enter 'Y' or 'N' to exit: Y 

    How many shares did you purchase? 50 

    What is the price per share? 50 

    Is this an online trade? Enter 'Y' or 'N': Y 

    Enter 'Y' to calculate the cost of another stock purchase or 'N' to exit: N 

    YEE-TRADE, INC. 
    TOTAL COST OF STOCK PURCHASES 
    FOR Yassin 
    AS OF OCTOBRE 04, 2015 
    Total Stock Cost: $2500.0 
    Total Online Fees: $5.95 
    Total Commissions: $0.0 
    TOTAL COST: $2505.95 

    Thank you for suing Yee-Trade's stock purchase calculator! 
Смежные вопросы