Allow User To Change And View State Of Credit Card With Menu Driven Program

Apr 20, 2015

I am new to OOP, i am not sure if this is the correct approach or not. Write a class named CreditCard that has (at least) the following member variables:

- name. A String that holds the card holder's name.
- cardNumber. A field that holds the credit card number.
- balance. A double that stores the current credit card balance.
- spendingLimit. A double that stores the spending limit of the card holder.
- Bonus: additional fields that you can think of.

In addition, the class should have the following member functions:

- Constructor. The constructor should accept the card holder's name and card number and assign these values to the object's corresponding member variables. The constructor should initialize the spending limit to $2,000 and the balance to $0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's member variables.
- purchase. This function should add the amount specified as a parameter to the balance member variable each time it is called.
- increaseSpendingLimit. This function should add 500 to the spendingLimit member variable each time it is called.
- payBill. This function should reset the balance to 0.
- Input validation: Whenever a credit card number is modified, verify that it is of reasonable length.

Demonstrate the class in a program that creates a CreditCard object and allows the user to change and view the state of the credit card with a menu driven program.

View Card Information.

- Purchase an Item: ask the user the purchase amount and increase the card balance accordingly.
- Pay Bill: call payBill method to set the balance to 0.
- Increase Spending Limit: ask the user how much the spending limit should be, and call the increaseSpendingLimit function the appropriate number of times.

[CODE]

import java.io.*;
import java.util.Scanner;
public class CreditCard
{
Scanner input = new Scanner(System.in);
//data members
private String holderName;
private int cardNumber;
private int accountBalance;
private double spendingLimit;

[Code] ....

View Replies


ADVERTISEMENT

How To Change State Of Object - Main Method Exception Error

Jan 8, 2015

The error I get when I execute my java file.

Exception in thread "main" java.lang.NullPointerExceptionat DogTestDrive.main(DogTestDrive.java:19)

Here is the source

class Dog {
int size;
String name;
void bark () {
if (size < 60) {
System.out.println("Woof woof");

[code]....

Some background: I'm reading "Head first Java 2nd edition" and I'm going through the examples which is showing me how to change the state of an object. The original code looks like the code below, however the previous chapter went over creating array's of an object, so I created an array of the object "Dog" and wanted to re-write it this way. To my understanding, it should work but it's giving me that error when I execute it. The error itself isn't very clear, if I could get a line number pointed to, that would work.

class Dog {
int size;
String name;
void bark() {
if (size > 60) {
System.out.println(“Wooof! Wooof!”);
} else if (size > 14) {
System.out.println(“Ruff! Ruff!”);
} else {
System.out.println(“Yip! Yip!”);

[code]....

View Replies View Related

Change Frame And Focus In Card Layout

Feb 18, 2014

I'm nearing the final development stages of my first game, but have run into a problem. I've constructed 4 different levels and allow the user to select the level they want to play from a central JPanel in a Card Layout system. My problem is that once a level is completed, I can't switch the JPanel which is displayed to start the next level, since I don't know how to access the original JPanel which acts as a driver for the other panels.

MainFrame.java

Java Code:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;

[Code] ....

View Replies View Related

Change Frame And Focus In Card Layout From External Class / Trigger

Feb 18, 2014

I've constructed 4 different levels and allow the user to select the level they want to play from a central JPanel in a Card Layout system. My problem is that once a level is completed, I can't switch the JPanel which is displayed to start the next level, since I don't know how to access the original JPanel which acts as a driver for the other panels.

MainFrame.java
Java Code: import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related

How To Change Menu GUI With Buttons

Apr 23, 2014

I have a GUI with a menu to do various options. However I want to change that menu to use buttons instead. I'm working with JSwing components and I'm a little familiar with the JButton function, but I don't know how to convert the menu to a button. I think I'll have to remove the menu completely..anyway I tried to start with the file menu but the compiler says no suitable method found for setForeground(javax.swing.JMenu). Why is it giving me an error related to JMenu when I'm using Jbutton objects? Can I not use JButton objects inside a menubar scope? I'll bold the area it highlighted:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

[Code]...

View Replies View Related

Analog Clock - How To Use Menu To Change Alarm Time

May 10, 2014

the analog clock dese not move put it work when i run the program and the the buttoms dose not work i do not why how i can use the menu alarm to change the alarm time this my code run it.

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.Timer;

[code]....

View Replies View Related

Trading Card Game - Each Card Can Be Moved Around Like Chess Pieces

May 10, 2014

So I'm making a trading card game and each card can be moved around like chess pieces. So far, I've made the cards simple rectangles and detect if clicks are made within that rectangle and then move them appropriately, but I'm not sure if that's the best solution.

View Replies View Related

JSP :: Displaying Different Menu According To Specific User On Same Page

Sep 24, 2014

i am beginner in java and i am making an application in which i want to display menu for 3 different types of users. like when we login i want to check which type of user is this and which menu to show them. for ex. if there is a employee the menu bar has a dropdown which shows activities like fill nomination, see details etc. if it privileged user he is shown a diff menu and if its the admin the dropdown shows some different activities. i want to make it through simple jsp and servlet. i have a table in data base which has types of user predefined with an id how to display that menu according to a specific user.

View Replies View Related

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Jasper Report Is Only Showing Code (source View) Instead Of Design View

Mar 23, 2014

I am building a room management system in Java (Netbeans) and Ms Access. The jasper report is only showing code (source view) instead of design view. The GUI JFrame and Login JFrame are not displaying records in the database and the buttons are not working. Also the labels and text fields are not neatly arranged. The connection to the database is not displaying records.

Connection to the database. COIRMS.java

package Login;
import java.sql.*;
public class COIRMS {
Connection con;
Statement st;
ResultSet rs;
public COIRMS ()

[Code] ....

View Replies View Related

Program That Links Several GUI As Menu Based Program

Dec 17, 2014

In a project for school. I have a program that links several GUI's as a menu based program. What I am trying to accomplish is when one of the previous GUI's is closed that it doesn't terminate the entire program. There is a lot of classes in the entire project so I'd prefer not to paste all the code here, but if it is necessary I will do so.

View Replies View Related

Reading Json Of Nested Menu Without Giving Menu Names In Java

Aug 14, 2014

I want to read json file as follow;
 
{
  "M": {
  "row": [
  {
  "col1": "c00"
  },
  {
  "col1": "c10",
  "col2": "c11"
  },
  {
  "col1": "c20",
  "col2": "c21",
  "col3": "c22"
  }
  ]
  }
}
 
Next to reading I need to assign to two dimensional array, but without giving "col1","col2","col3" a lot. 

The array is for example, Array[3][] = {{"c00"},{"c10","c11"},{"c20","c21","c22"}};

View Replies View Related

How To Go Back To Main Menu And Terminate A Program

Oct 15, 2014

How to go back to main menu and terminate a program?

I just want a Simple code.

View Replies View Related

Grading System Calculator - Calculate Grade Point Of Three Subjects And Their Credit Hours

Mar 14, 2014

Write a java program that calculate the grade point of three subjects and their credit hours through if the grade points and the credit hours are

Subject---grade---gradepoint-----credit hours
Maths------A--------4.0---------3
English composition-----B-------3.0-----2
French-----B+ ---- 3.3----------3

Now,if the grade point is equal to 4 ,print out First class
If the grade point is equal or greater than 3.0 but less than 4,print out Second class upper
If the grade point is equal or greater than 2.0 but less than 3,print out second class lower
Use the if-else-if statement

View Replies View Related

Dinner Menu Program - Some Text Is Not Showing On Applet

Dec 23, 2014

I have been writing the below Dinner Menu Applet; however some text is not showing on the applet and it is not adding the 'desserts" section correctly especially the one that says "rice Pudding". I've tried it in so many different ways and it's sill not working correctly.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class DinnerMenuApplet extends Applet implements ItemListener
{
Label dinnerMenu = new Label("Dinner Menu");

[code]....

View Replies View Related

Writing A Program Using Switch Statement - Allow Users To Choose Item Of A Menu

Oct 5, 2014

Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.

File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:

If you type 1, then your program should print out "Open is selected" (double quotes not included).

Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.

Here's what I have:

public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");

[Code] .....

View Replies View Related

Text Based RPG - Allow User To Change Their Name

Sep 26, 2014

String name = "Aaron";
String whatToChange = "name";
String verifyNameChange = "";
boolean changeName = false;

if(whatToChange.equals("name")){
while(!changeName){

[Code] ....

I've been working on a small text-based RPG for fun. This particular part is supposed to allow the user to change their name. Now, the problem is that when they reach the option to change their name, the above code seems to skip the line:

name = scan.nextLine();

It will erase whatever the player previously entered for their name, as well. So it will print out:

Okay, let's change your name. What did you say it was? Alright, so you'll go by . Is that correct? [now allows input for verifyNameChange]

The above code works fine on it's own, but somehow messes up when put into the full program. I don't want to post the whole program, because it's fairly large. But the String name is set and functions fine before this bit of code.

View Replies View Related

Database Driven CD Collection App

Feb 27, 2014

I am using mysql database and I have downloaded the library also I have managed to get the database connection and query working. I need to know if I need to create separate classes to add/remove/edit items and view items? Do I need to put my database connection script in every class that I create or should I create methods for both the connection and the queries that will be called in the additional classes or methods that I have?

Below is what I have written so far and it is working, I will change the database and query soon to reflect the task I need to do because I have followed a tutorial.

Java Code:

/**
* cdCollection.java
*/
package org.com.mm00422_prototype;
//Import for the SQL package
import java.sql.*;

//Registering the JDBC driver
//Class.forName("com.mysql.jdbc.Driver");

[code]....

View Replies View Related

Swing/AWT/SWT :: Event Driven Development

Feb 22, 2014

I think will be easy for me start with a GUI and then make things happens when the user clic on Buttons.Is there a good book about Event driven development on Java?

View Replies View Related

Deploying Data Driven Java App

Dec 10, 2014

I have created a database driven Java app that i would like to deploy to several PCs. The App uses JReports which only worked when i installed Javac on this laptop. It worked fine within Netbeans but after building it depended on the java compiler and only worked after setting up Path variable..

Will i need to setup the Javac on every machine or is there any way of deploying it easier?

View Replies View Related

How To Change Value In Array Through User Input And Print Out Result

Dec 14, 2014

I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :

1)enter which car he wanna move,
2)what direction (w,a,s,d) and after that,
3) how many moves( not out of bound) he wants to make, and finally
4) we print out the new parking lot for his next move

And i am stuck at how to move the car to corresponding position and then prompt user for the next move?

For example:

I want to move A to the right by 1 (d)

擷取.PNG
print result:
擷取1.PNG

How do I do that? The code that i have right now

public class CarParkGame {
public static void main( String [] args) {
  String carPark[][] = new String [6][6] ;
carPark[0] = new String[] {"A","A","A","0","0","0"};
carPark[1] = new String[] {"b","0","0","0","0","c"};
carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};

[Code] .....

View Replies View Related

Directly Change Java Code Using User Input

Nov 16, 2014

I'm quite new to java programming, but eager to learn. I was wondering how to change actual java code, using user input. For example:

Java Code: int x = 0;
// Start the program and enter 3
// Now the code is
int x = 3 mh_sh_highlight_all('java');

View Replies View Related

Create A Menu Where The User Can Create A New Account?

Oct 5, 2014

I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.

Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank

/*---------------------------------------------------
Plagiarism Statement
 
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
 
----------------------------------------------------------*/ 

package BankAccount;
 import java.util.Date;
import java.util.Random;
 //Project 3
public class BankAccount {
protected static int accountID;

[code]....

View Replies View Related

Event Driven Programming / No Main Method

Jan 29, 2015

I'm reading a book titled 'Intro to Java Programming'. I understand all the Main Method stuff. I'm now reading a chapter that talks about event driven programming. I know how to do this in VBA and in C#, ut I can't figure out how this works in Java. Here's the sample code that I'm trying to run.

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

[code]....

I'm using Net Beans IDE. When I paste that code into the IDE, I get all kinds of errors. Also, since there is no Main, I don't know how this is supposed to run. Java needs a Main Method for everything, I think. Does the Main call some kind of class?

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Java Program That Will Ask A User To Input Grades Until User Inputs Sentinel Value

Apr 9, 2014

Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved