Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Q4;
- import java.util.Scanner;
- public class flowerCounter {
- public static void main(String[]args){
- Scanner kb = new Scanner(System.in);
- String asking;
- int quantity;
- double sum;
- int counter = 0;
- String [] flower = new String [5];
- double [] cost = new double [5];
- flower [0] = "Petunia";
- flower [1] = "Pansy";
- flower [2] = "Rose";
- flower [3] = "Violet";
- flower [4] = "carnation";
- cost [0] = 0.50;
- cost [1] = 0.75;
- cost [2] = 1.50;
- cost [3] = 0.50;
- cost [4] = 0.80;
- System.out.print("What flower do you desire: ");
- asking = kb.nextLine();
- if(!(asking.equals(flower[0]) || asking.equals(flower[1]) || asking.equals(flower[2]) || asking.equals(flower[3]) || asking.equals(flower[4]))){
- System.out.print("Sorry we dont sell those \n");
- System.exit(0);
- }
- System.out.printf("how many %s do you want? ", asking);
- quantity = kb.nextInt();
- for(counter = 0 ; counter <=5 ; counter++){
- if(asking.equals(flower[counter])){
- sum = cost[counter] * quantity;
- System.out.print("$ "+sum+"\n");
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment