Kevin321888999

Meal Card

Nov 15th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.util.Scanner;
  2. class MealCard{
  3.     static int initial_Balance=200;
  4.     private String Student_Name;
  5.  
  6.     private int Student_ID;
  7.     private int costofitem;
  8.     Scanner SC=new Scanner(System.in);
  9.     public MealCard(){
  10.  
  11.        Student_Name=SC.nextLine();
  12.        Student_ID=SC.nextInt();
  13.        costofitem=SC.nextInt();
  14.  
  15.        System.out.println("The student's name: "+ Student_Name);
  16.        System.out.println("Student ID number: "+ Student_ID);
  17.        System.out.println("Initial Balance : "+ MealCard.getInitial_Balance());
  18.  
  19. if(getPay(costofitem)>5){
  20.        System.out.println("Payment accepted! Your final balance is: "+ getPay(costofitem));}
  21.     }
  22.     public static int getInitial_Balance() {
  23.         return initial_Balance;
  24.     }
  25.     public static int getPay(int a) {
  26.         int finalbalance = initial_Balance - a;
  27.         if(finalbalance<5){
  28.             System.out.println("This is too low of a balance! Payment Rejected!");
  29.             System.out.println("Warning: balance is too low! Must deposit more money into school account.");
  30.         }
  31.         else;
  32.         return finalbalance;
  33.     }}
  34.  
  35.  
  36. public class Homework4Question3{
  37.     public static void main(String[] args ){
  38.         NameTag();
  39.         for(int i=0;i<5;i++){
  40.             System.out.println("Please enter the name of the student, the ID, and the cost of the item you want.");
  41.         MealCard StudentMealPlan=new MealCard();}
  42.     }
  43.     public static void NameTag(){
  44.         System.out.println("Malachi Sor Homework 4 Question 3\n--------------------------\n");
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment