Java need help

0 Claude Mona · September 24, 2015
Need help writing this code that answers the following 
Calculate the subtotal, total tax, and total price, and display it on the screen. 
Ask the user how they would like to pay for the lemonade, and save the input as a char variable. 
Ask the user to enter either 'm' for money, 'c' for credit card, or 'g' for gold 
Using the DecimalFormat class, make all currency data printed to the screen display 2 decimal places, and also a '$" sign. 

This is what I have so far : 

import java.util.Scanner; 

public class FirstProgram { 

public static void main(String[] args) { 
double cost; 
cost = 7.55; 
Scanner input = new Scanner(System.in); 

System.out.println("Welcome to the best Lemonade you'll ever taste! "); 

System.out.println("My lemonade would only cost you a measly: $" + cost); 

System.out.println("What is your name?"); 

String first_name; 
first_name = input.nextLine(); 

System.out.println("Hi " +first_name+ ", how many glasses of lemonade would you like?");

Post a Reply

Replies

Oldest  Newest  Rating
0 Neil Cannon · October 8, 2015
package doyourhomeworkyourself;

import java.util.Scanner;

public class FirstProgram {
   

    public static void main(String[] args) {

        float cost;
        
        cost = 7.55f;
        // tax = 0.25;
        

        Scanner input = new Scanner(System.in);

        System.out.println("WELCOME to the best Lemonade you'll ever taste! ");

        System.out.println("\nMy lemonade would only cost you a measly: $" + cost + " plus tax");

        System.out.println("What is your name?");

        String first_name;
        first_name = input.nextLine();

        System.out.println("\nHi " + first_name + ", how many glasses of lemonade would you like?");

        try (Scanner in = new Scanner(System.in)) {
            int x = in.nextInt();

            System.out.println("The cost of " + x + " glasses of lemonade will be $" + cost * x);

            System.out.println("Would you like to pay by Money(M) or Card(C) or Gold(G)?");
            String payment = in.next();

            System.out.println("You have decided to pay with " + payment);
 
            System.out.println("The sub total is $" + (cost*x));
            System.out.println("The tax is $" + (cost*x*0.25f%2));
            System.out.println("The total payment for the lemonade is " + (cost*x + cost*x*0.25f%2));
        }  

          
    }
}



Still needs some work doing on this program, but hey you can finish it off!
0 ishwiin doe · October 9, 2015
package jdsbvdjsgbv;
import java.util.Scanner;
import java.text.DecimalFormat;
public class ahshs {
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     DecimalFormat df = new DecimalFormat("#.00");
     double cost;
System.out.println("now it will print the way you want it to $" + df.format(cost))'
  • 1

Java / Android Development

107,255 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator