christopher pam

Greenhorn
+ Follow
since Jan 12, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by christopher pam

import java.util.Scanner;

public class Account
{
private double balance;
private double withdrawal;

public Account(double initialBalance)
{
if(initialBalance > 0.0)
balance = initialBalance;

if(withdrawal < 25000.00)
withdrawal = balance;
else
{
System.out.print("Debit amount exceeded account balance");
}
}
public void debit(double withdrawal)
{
balance = balance - withdrawal;
}

public void credit(double amount)
{
balance = balance + amount;
}

public double getBalance()
{
return balance;
}

public static void main(String args[])
{
Account account = new Account(25000.00);

Scanner input = new Scanner(System.in);
double depositAmount;
double withdrawalAmount;


System.out.printf("You've got $%.2f in your account\n",account.getBalance());

System.out.print("Enter deposit amount");
depositAmount = input.nextDouble();
System.out.printf("nAdding %.2f to the account concerned\n\n",depositAmount);
account.credit(depositAmount);
System.out.printf("You've got $%.2f in your account\n",account.getBalance());



System.out.print("Enter withdrawal amount");
withdrawalAmount = input.nextDouble();
System.out.printf("nDeducting $%.2f from the account concerned\n\n",withdrawalAmount);
account.debit(withdrawalAmount);
System.out.printf("You've got $%.2f in your account\n",account.getBalance());
}
}


the above code is supposed to give me ma account balance and prompt me to enter a deposit amount which it'll add up to the initial balance and afterwards prompt me to enter withdrawal amount,now this is where ma problem lies.im tryin to ensure that the debit amount does not exceed the account's balance,if it does the balance is to be left unchanged and printing a message indicating "Debit amount exceeds account balance".instead it keeps leaving the account with a negative balance.what do i do?
14 years ago
i have another problem,here's a code i just got from a book;


public class Grade
{
private String courseName(String name);

public void setCourseName(String name)
{
courseName = name;
}

public String getCourseName()
{
return courseName;
}

public void displayMessage()
{
System.out.printf("Welcome to the grade book for\n%s,getCourseName());
}

public static void main(String args[])
{
Scanner input = new Scanner(System.in);

Grade myGrade = new Grade();

System.out.println("Initial course name was Architecture");
System.out.println();

System.out.println("Please enter the course name:");
String name = input.nextLine();
myGrade.setCourseName(name);
System.out.println();
myGrade.displayMessage();
}
}



setCourseName,considering the fact that it is void which means it shouldnt return any data when it completes task,but in this case i think it does cos the method's being called from the main method(myGrade.setCourseName) and thats when the program prompts you to enter course name after executing.after keying in the course name data is then returned to the system for the line "Welcome to the grade book for ......" to display when the displayMessage is invoked.am i right?
14 years ago
Giving a situation where we have;

public class GradeBook
{
private String courseName;

public void setCourseName(String name)
{
--------------------------;
}

courseName being a private instance variable should only be accessed and manipulated by methods of thesame class,like setCourseName.wouldnt it be possible to access it(courseName)with a method of another class that can call the method setCourseName?if this is possible then i think the whole purpose of the private keyword which is data hiding will be defeated.could really use some help concerning this,thanks
14 years ago
hi,is it possible to declare the parameter list of a method with more than one type like say "public void displayMessage(String courseName.Int courseGradePointAverage)"?
14 years ago
hi,is it possible to declare the parameter list of a method with more than one type like say "public void displayMessage(String courseName.Int courseGradePointAverage)"?
14 years ago