Kevin321888999

MealCard

Nov 16th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Homework4Question3{
  5.     public static void main(String[] args ){
  6.         Scanner SC=new Scanner(System.in);
  7.         int costofitem;
  8.         int DepositMoney;
  9.  
  10.         NameTag();
  11.  
  12.         MealCard Student1=new MealCard("Malachi Sor",200181 );
  13.         MealCard Student2= new MealCard("Charlie Koepke",305812);
  14.         MealCard Student3= new MealCard("Jon Gessick ",343343 );
  15.         MealCard Student4= new MealCard("Matt Fleischman", 232632);
  16.         MealCard Student5= new MealCard("Emma Lopez", 234532);
  17.  
  18.      
  19.        System.out.println("How much does Malachi want to spend?");
  20.        costofitem=SC.nextInt();
  21.        Student1.Payment(costofitem);
  22.        Student1.DisplayInfo();
  23.  
  24.        System.out.print("How much does Charlie want to spend? ");
  25.        costofitem = SC.nextInt();
  26.        Student2.Payment(costofitem);
  27.        Student2.DisplayInfo();
  28.  
  29.        System.out.print("\nHow much does Jon spend? ");
  30.        costofitem = SC.nextInt();
  31.        Student3.Payment(costofitem);
  32.        Student3.DisplayInfo();
  33.  
  34.         System.out.print("\nHow much does Matt want to pay? ");
  35.         costofitem = SC.nextInt();
  36.         Student4.Payment(costofitem);
  37.         Student4.DisplayInfo();
  38.  
  39.         System.out.print("\nHow much does Emma want to pay? ");
  40.         costofitem = SC.nextInt();
  41.         Student5.Deposit(costofitem);
  42.         Student5.DisplayInfo();
  43.  
  44.  
  45.     }
  46.     public static void NameTag(){
  47.         System.out.println("Malachi Sor Homework 4 Question 3 \n--------------------------");
  48.     }
  49. }
  50.  
  51. class MealCard{
  52.     private int Balance=200;
  53.     private String Student_Name;
  54.     private int Student_ID;
  55.  
  56.  
  57.     public MealCard(String StudentName, int StudentID){
  58.         Student_Name=StudentName;
  59.         Student_ID=StudentID;
  60.         DisplayInfo();
  61.     }
  62.     public void DisplayInfo(){
  63.         System.out.println("The student's name: "+ this.Student_Name);
  64.         System.out.println("Student ID number: "+ this.Student_ID);
  65.         System.out.println("Balance : "+ this.Balance);
  66.         System.out.println("-----------------------------------------");
  67.     }
  68.  
  69.     public int getBalance() {
  70.         return Balance;
  71.     }
  72.     public void Payment(int a) {
  73.         if(a>Balance){
  74.             System.out.println("You do not have enough money");
  75.         }else{
  76.             Balance-=a;
  77.             if(Balance<5){
  78.                 System.out.println("Warning: balance is too low! Must deposit more money into school account.");
  79.             }
  80.         }
  81.  
  82.     }
  83.     public void Deposit(int b){
  84.         Balance+=b;
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment