473,667 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Exercise

6 New Member
Hi, I have an exercise I need to do for Java. I am not sure how to start this program. Can somebody help me get started on this problem? Thanks in advance for your help. The problem is as follows:
Develop a Java application that will determine whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a) account number
b) balance at the beginning of the month
c) total of all items charged by the customer this month.
d) total of all credits applied to the customer's account this month.
e) allowed credit limit.

The program should input all these facts as integers, calculate the new balance(= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit limit exceeded"
Oct 30 '06 #1
3 9461
r035198x
13,262 MVP
Hi, I have an exercise I need to do for Java. I am not sure how to start this program. Can somebody help me get started on this problem? Thanks in advance for your help. The problem is as follows:
Develop a Java application that will determine whether any of several department-store customers has exceeded the credit limit on a charge account. For each customer, the following facts are available:
a) account number
b) balance at the beginning of the month
c) total of all items charged by the customer this month.
d) total of all credits applied to the customer's account this month.
e) allowed credit limit.

The program should input all these facts as integers, calculate the new balance(= beginning balance + charges - credits), display the new balance and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the message "Credit limit exceeded"
Start by working on how to get the input and store in conveniently.
Oct 30 '06 #2
Dave128
6 New Member
Here is code I started but I am getting errors. Can anybody help me get this problem corrected?

[/code]
import java.util.Scann er;

public class CreditCheck
{
Scanner input = new Scanner( System.in );
// define instance variable
int acctNo = 0;
double shopinitA = 0.0;// initial balance
double shopcharges = 0.0; // charges applied to user's acct
double shopcredits = 0.0; // credits applied to user's acct
double shopcreditlimit = 0.0; // user's acct limit
double newbal = 0.0; //user's calculated balance
double positivecredit = 0.0; // money left to spend
double negativecredit = 0.0; // amount of money overdrawn
String msg = "";

public CreditCheck()
{
}

//acct number based on user's input
public void setAccountNumbe r (int acctNo)
{
acctNo = acctNo;
}

//method for initial balance on user's input
public void setInitialBalan ce (double initA)
{
shopinitA = initA;
}

// method to establish total charges based on user's input
public void setTotalCharges (double charges)
{
shopcharges = charges;
}

// method establishes total credits based on user's input
public void setTotalCredits (double credits)
{
shopcredits = credits;
}

//method establishes total credit based on user's input
public void setCreditLimit (double creditLimit)
{
shopcreditlimit = creditLimit;
}


// balance calculation and results
public void showResult()
{
//calculate balance
newbal = (shopinitA + shopcharges)- shopcredits;
positivecredit = shopcreditlimit - newbal;
negativecredit = shopcreditlimit - (newbal);



//user balance options
if ( newbal < 0 )
System.out.prin t( "Your balance is $" , newbal(positive credit) +"to spend.");

else if ( positivecredit >=0 )
System.out.prin t( "Your balance is $" , newbal + "\n and you still have $");

else
System.out.prin tln ("Credit Limit exceeded" );
}

}
Nov 1 '06 #3
r035198x
13,262 MVP
Here is code I started but I am getting errors. Can anybody help me get this problem corrected?

[/code]
import java.util.Scann er;

public class CreditCheck
{
Scanner input = new Scanner( System.in );
// define instance variable
int acctNo = 0;
double shopinitA = 0.0;// initial balance
double shopcharges = 0.0; // charges applied to user's acct
double shopcredits = 0.0; // credits applied to user's acct
double shopcreditlimit = 0.0; // user's acct limit
double newbal = 0.0; //user's calculated balance
double positivecredit = 0.0; // money left to spend
double negativecredit = 0.0; // amount of money overdrawn
String msg = "";

public CreditCheck()
{
}

//acct number based on user's input
public void setAccountNumbe r (int acctNo)
{
acctNo = acctNo;
}

//method for initial balance on user's input
public void setInitialBalan ce (double initA)
{
shopinitA = initA;
}

// method to establish total charges based on user's input
public void setTotalCharges (double charges)
{
shopcharges = charges;
}

// method establishes total credits based on user's input
public void setTotalCredits (double credits)
{
shopcredits = credits;
}

//method establishes total credit based on user's input
public void setCreditLimit (double creditLimit)
{
shopcreditlimit = creditLimit;
}


// balance calculation and results
public void showResult()
{
//calculate balance
newbal = (shopinitA + shopcharges)- shopcredits;
positivecredit = shopcreditlimit - newbal;
negativecredit = shopcreditlimit - (newbal);



//user balance options
if ( newbal < 0 )
System.out.prin t( "Your balance is $" , newbal(positive credit) +"to spend.");

else if ( positivecredit >=0 )
System.out.prin t( "Your balance is $" , newbal + "\n and you still have $");

else
System.out.prin tln ("Credit Limit exceeded" );
}

}
The errors were caused by the incorrect print statements. I suppose you are going to write the main method for testing the logic of your solution?



Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class CreditCheck
  4. {
  5. Scanner input = new Scanner( System.in );
  6. // define instance variable
  7. int acctNo = 0;
  8. double shopinitA = 0.0;// initial balance
  9. double shopcharges = 0.0; // charges applied to user's acct
  10. double shopcredits = 0.0; // credits applied to user's acct
  11. double shopcreditlimit = 0.0; // user's acct limit
  12. double newbal = 0.0; //user's calculated balance
  13. double positivecredit = 0.0; // money left to spend
  14. double negativecredit = 0.0; // amount of money overdrawn
  15. String msg = "";
  16.  
  17. public CreditCheck()
  18. {
  19. }
  20.  
  21. //acct number based on user's input
  22. public void setAccountNumber (int acctNo)
  23. {
  24. acctNo = acctNo;
  25. }
  26.  
  27. //method for initial balance on user's input
  28. public void setInitialBalance (double initA)
  29. {
  30. shopinitA = initA;
  31. }
  32.  
  33. // method to establish total charges based on user's input
  34. public void setTotalCharges (double charges)
  35. {
  36. shopcharges = charges;
  37. }
  38.  
  39. // method establishes total credits based on user's input
  40. public void setTotalCredits (double credits)
  41. {
  42. shopcredits = credits;
  43. }
  44.  
  45. //method establishes total credit based on user's input
  46. public void setCreditLimit (double creditLimit)
  47. {
  48. shopcreditlimit = creditLimit;
  49. }
  50.  
  51.  
  52. // balance calculation and results
  53. public void showResult()
  54. {
  55. //calculate balance
  56. newbal = (shopinitA + shopcharges)- shopcredits;
  57. positivecredit = shopcreditlimit - newbal;
  58. negativecredit = shopcreditlimit - (newbal);
  59.  
  60.  
  61.  
  62. //user balance options
  63. if ( newbal < 0 )
  64. System.out.print( "Your balance is $" + newbal +"(positivecredit)to spend.");
  65.  
  66. else if ( positivecredit >=0 )
  67. System.out.print( "Your balance is $"+ newbal + "\n and you still have $");
  68.  
  69. else
  70. System.out.println ("Credit Limit exceeded" );
  71. }
  72.  
  73. }
Nov 2 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
10842
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the absolute file name of a .class file eg. C:\myJava\myApp.java, then how do i translate this file name to a java class name the Object.forName method would accept has it's parameter? thanks,
54
17394
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I give interviewees seems to trip them up all the time, and I wonder if I'm being too much of a hardass... it seems easy enough to ME, but these guys, when I get them up to the whiteboard, seem to get really confused. The exercise is this:
0
1203
manuleka
by: manuleka | last post by:
hi, got this Java exercise package and don't know where to start! could anyone help... a little explaining will be helpfull... not really familiar with Java Exercise Java Package (ziped): http://skux.cokenut.net/cods/Exercise_RentalShop.zip Exersise Spec: http://skux.cokenut.net/cods/RentalShop_Spec.doc
5
3031
by: ebrimagillen | last post by:
Hello mates, Just needed a solution on the exercises below. Exercise 2 A classic problem in introductory programming is the grains of rice on a chess board problem. Your program should calculate the number of rice grains on the last square of a 64 square chess board given that there is 1 grain of rice on the first square, 2 on the second square, 4 on the third square and so on. Use a while loop to double the number of rice grains and...
15
2785
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
2
3973
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: D:\original\CaseStudy-2-5\CaseStudy\Day02\exercise>asant database Buildfile: build.xml env-user: prop-user: set-user:
1
4817
by: alternative49e | last post by:
Hello. I'm trying to figure out an exercise. I started working on it but I kind of hit a wall. I'm not very good at the programming thing and the book I have is not very helpful. I could use some help or suggestions. I dont know if what I have started so far is even the correct way to do this. Here is exercise. Create a class called CarRental that contains fields that hold a renter's name, zip code, size of the car rented, daily rental fee,...
1
3700
by: gypsyman58 | last post by:
First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method to get a course. It does this by taking an integer and returning the course to that position (0 through 4). Then I must create a set method that sets the value of one of the courses by taking two arguements a name and an integer and returning the...
2
7372
by: cioccolatina | last post by:
Hey guys, is there anyone who could help me..? I have file ExpressionBinaryTree.java : /** class ExpressionBinaryTree * uses a binary tree to represent binary expressions * does not implement BinaryTree - all iterators return String */ package foundations;
0
8883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.