1 Replies - 6015 Views - Last Post: 14 February 2011 - 08:23 PM Rate Topic: -----

#1 Guest_michele*


Reputation:

vending machine & grade calculator

Posted 14 February 2011 - 07:57 PM

Write a program that simulates a vending machine. The machine holds six items numbered 1 through 6, with prices $1.25, $.75, $.90, $.75, $1.50, and $.75, respectively. The input to your program is an integer and a floating-point number representing an item number and a sum of money. If the money is enough to buy the item, your program should print:
“Thank you for buying item X. Your change is Y.”
If the money inserted is insufficient, then your program should say so. The following display gives typical output:
Enter an item number and a sum of money: 3 1.00
Thank you for buying item 3. Your change is $.10

Enter an item number and a sum of money: 6 0.25
Please insert another $.50


for the first code, It does work, but I don't feel that it works the way its suppose to. for the second code i'm just totally lost, I feel like my teacher left out some information.
import javax.swing.JOptionPane;
   public class Vmachine{
      public static void main(String[]args){
      // Declare variables
         String input1;
         String input2;
         float sum;
         float price; 
         int item;
      //prompt the user for input
         input1 = JOptionPane.showInputDialog("Enter an item");
         item= Integer.parseInt(input1);
         input2 = JOptionPane.showInputDialog("Enter a price amount");
         price=Integer.parseInt(input2);
         sum = price + item;
      //
         switch(item){
            case 1:
               JOptionPane.showInputDialog("Enter an item number and sum of money");
               break;
         
            case 2:
               JOptionPane.showInputDialog("Enter a number and sum of money");
               JOptionPane.showInputDialog("insufficient funds please enter another 50.cents");
               break;
         
            case 3:
               JOptionPane.showInputDialog("Enter a number and sum of money");
               JOptionPane.showInputDialog("insufficient funds please enter another 50.cents");
               break;
         
            case 4:
               JOptionPane.showInputDialog("Enter a number and sum of money");
               break;
         
            case 5:
               JOptionPane.showInputDialog("Enter a number and sum of money");
               break;			
            case 6:
               JOptionPane.showInputDialog("Enter a number and sum of money");
               break;
         }
      }	
   }
              
	
 Write a program that will calculate your letter grade in the class. You will need the following for the calculations:

	Lab assignments		20%
	Lab exams/Class exams	25%
	Homework/Quizzes/Projects 30%
	Final exam			25%

Final letter grades will be based on the following scale:
A: 90 to 100  B:80 to 89  C:70 to 79  D:60 to 69  F:less than 60


	
import java.util.Scanner;
   public class Calculator{
      public static void main(String []args){
      //declare variables
      
         int lab;
         int ce;
         int quiz;
         int exam;
         lab=.2;
         ce=.25;
         quiz=.30;
         exam=.30;
      //create a scanner object
         Scanner input= new Scanner(System.in);
      
         System.out.println("Enter in lab percentage");
         lab= input.nextInt();
         System.out.println("Enter in ce percentage");
         ce=input.nextInt();
         System.out.println("Enter in quiz percentage");
         quiz= input.nextInt();
         System.out.println("Enter in exam percentage");
         exam= input.nextInt();
      
   
      
      
      }
   }


This post has been edited by macosxnerd101: 14 February 2011 - 10:30 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0

Replies To: vending machine & grade calculator

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: vending machine & grade calculator

Posted 14 February 2011 - 08:23 PM

Please :code:
And what is your question ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1