lundi 24 octobre 2016

What if the user enters any int less than 600, the program will always choose standard talk

import java.util.Scanner;
import java.text.DecimalFormat;

public class Java_Lab_2 {
    public static void main(String[] args) {    
        Scanner kb = new Scanner(System.in);    

        DecimalFormat f = new DecimalFormat("0.00");

        int userMin;        
        int basicTalkMin = 400;         
        int standTalkMin = 600;         
        final double basicCharge = .35;         
        final double standCharge = .30;         
        double basicTotal;      
        double standTotal;      
        final double unlTotal = 60.00;      
        final double basicCost = 30.00;         
        final double standCost = 40.00;         
        final double unlimCost = 60.00;                 
        System.out.println("How many minutes do you expect to talk per month?");
        userMin = kb.nextInt();
        basicTotal = ((userMin - basicTalkMin) * (basicCharge) + (basicCost));  
        standTotal = ((userMin - standTalkMin) * (standCharge) +    (standCost));

        if (basicTotal < standTotal && basicTotal < unlTotal)
            System.out.println("The best plan(s) for you is Basic Talk.\nExpect to pay:$ " + (f.format(basicTotal)));
        else if (standTotal < basicTotal && standTotal < unlTotal)
            System.out.println("The best plan(s) for you is Standard Talk.\nExpect to    pay:$ " + (f.format(standTotal)));
        else if (unlTotal < basicTotal && unlTotal < standTotal)    
            System.out.println("The best plan(s) for you is Unlimited Talk.\nExpect   to pay:$ " + (f.format(unlTotal)));
        else
            System.out.println("You should not buy a calling plan.\nExpect to  pay:$0.00");
    }
}

Aucun commentaire:

Enregistrer un commentaire