Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Homework4Question3{
- public static void main(String[] args ){
- Scanner SC=new Scanner(System.in);
- int costofitem;
- int DepositMoney;
- NameTag();
- MealCard Student1=new MealCard("Malachi Sor",200181 );
- MealCard Student2= new MealCard("Charlie Koepke",305812);
- MealCard Student3= new MealCard("Jon Gessick ",343343 );
- MealCard Student4= new MealCard("Matt Fleischman", 232632);
- MealCard Student5= new MealCard("Emma Lopez", 234532);
- System.out.println("How much does Malachi want to spend?");
- costofitem=SC.nextInt();
- Student1.Payment(costofitem);
- Student1.DisplayInfo();
- System.out.print("How much does Charlie want to spend? ");
- costofitem = SC.nextInt();
- Student2.Payment(costofitem);
- Student2.DisplayInfo();
- System.out.print("\nHow much does Jon spend? ");
- costofitem = SC.nextInt();
- Student3.Payment(costofitem);
- Student3.DisplayInfo();
- System.out.print("\nHow much does Matt want to pay? ");
- costofitem = SC.nextInt();
- Student4.Payment(costofitem);
- Student4.DisplayInfo();
- System.out.print("\nHow much does Emma want to pay? ");
- costofitem = SC.nextInt();
- Student5.Deposit(costofitem);
- Student5.DisplayInfo();
- }
- public static void NameTag(){
- System.out.println("Malachi Sor Homework 4 Question 3 \n--------------------------");
- }
- }
- class MealCard{
- private int Balance=200;
- private String Student_Name;
- private int Student_ID;
- public MealCard(String StudentName, int StudentID){
- Student_Name=StudentName;
- Student_ID=StudentID;
- DisplayInfo();
- }
- public void DisplayInfo(){
- System.out.println("The student's name: "+ this.Student_Name);
- System.out.println("Student ID number: "+ this.Student_ID);
- System.out.println("Balance : "+ this.Balance);
- System.out.println("-----------------------------------------");
- }
- public int getBalance() {
- return Balance;
- }
- public void Payment(int a) {
- if(a>Balance){
- System.out.println("You do not have enough money");
- }else{
- Balance-=a;
- if(Balance<5){
- System.out.println("Warning: balance is too low! Must deposit more money into school account.");
- }
- }
- }
- public void Deposit(int b){
- Balance+=b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment