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"
3 9461
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.
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" );
}
}
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? - import java.util.Scanner;
-
-
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 setAccountNumber (int acctNo)
-
{
-
acctNo = acctNo;
-
}
-
-
//method for initial balance on user's input
-
public void setInitialBalance (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.print( "Your balance is $" + newbal +"(positivecredit)to spend.");
-
-
else if ( positivecredit >=0 )
-
System.out.print( "Your balance is $"+ newbal + "\n and you still have $");
-
-
else
-
System.out.println ("Credit Limit exceeded" );
-
}
-
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,
|
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:
|
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
|
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...
|
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, )
| |
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:
|
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,...
|
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...
|
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;
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |