“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

New Topic/Question
Reply
MultiQuote






|