Question

This material is somewhat more theoretical than that of previous topics, so instead of writing a...

This material is somewhat more theoretical than that of previous topics, so instead of writing a program for this assignment, you are going to work on a design. Specifically, your task is to design a Java class to represent a credit card. Try to design your class such that it only includes fields and methods relevant to a credit card itself, without branching out into related functionality, like that of a bank or a consumer. At the same time, try to make your class as complete as possible, so that it can be used in any application that involves a credit card.

To complete this assignment, you will turn in a text document (Word or .pdf) with the following information:

 A list of the fields and methods of your class. For fields you will need to specify the type, the accessibility (private, public, protected, default or package), whether it is a static or instance field, and any limitations on the values (non-negative, always less than some other value, etc.). For the methods, you will need to supply the return type and parameter type list.

 A free-form description of what each field and method is meant to do, with explanation of any potentially confusing design decisions.

 A justification for your design based on the guidelines given in Section 13.10 of your textbook on pages 525-528.

The first two items will look somewhat similar to what was provided in the assignment description for Fourth Assignment – Calculator with Methods. The justification will be somewhat similar to what was provided in the URL.java file included in this topic’s course materials (week10.jar). You do NOT need to implement your class (i.e., you do not need to write any code).

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Answer:--- Date:--26/13/2019

mport java.util.Scanner;
public class CalcWithMethods {
/**
* @param args
*/
public static int getMenuOption() {
int userInput;
Scanner scannerObj = new Scanner(System.in);
int counter = 0;
System.out.println("\nMenu");
System.out.println("1. Add");
System.out.println("2. Subtract");
System.out.println("3. Multiply");
System.out.println("4. Divide");
System.out.println("5. Generate Random Number");
System.out.println("6. Quit");
System.out.println("Please select a number between 1-6");
userInput = scannerObj.nextInt();
while (userInput < 1 || userInput > 6) {
if (counter >= 3) {
System.out.println("ERROR: Threshold of 3 invalid menu inputs reached. Please try again later");
System.exit(1);
}
System.out.println("Error: Enter a number between 1-6");
userInput = scannerObj.nextInt();
counter++;
}
return userInput;
}
public static double add(double operand1, double operand2) {
return operand1 + operand2;
}
public static double subtract(double operand1, double operand2) {
return operand1 - operand2;
}
public static double multiply(double operand1, double operand2) {
return operand1 * operand2;
}
public static double divide(double operand1, double operand2) {
if (operand2 == 0) {
return Double.NaN;
}
return operand1 / operand2;
}
public static double random(double lowerLimit, double upperLimit) {
return (lowerLimit + (double) (Math.random() * upperLimit));
}
public static double getOperand(String prompt) {
Scanner scannerObj = new Scanner(System.in);
System.out.println(prompt);
return scannerObj.nextDouble();
}
public static void main(String[] args) {
int userInput;
do {
userInput = getMenuOption();
switch (userInput) {
case 1: {
System.out
.println("Answer: " + add(getOperand("Enter first number"), getOperand("Enter Second Number")));
break;
}
case 2: {
System.out.println(
"Answer: " + subtract(getOperand("Enter first number"), getOperand("Enter Second Number")));
break;
}
case 3: {
System.out.println(
"Answer: " + multiply(getOperand("Enter first number"), getOperand("Enter Second Number")));
break;
}
case 4: {
System.out.println(
"Answer: " + divide(getOperand("Enter first number"), getOperand("Enter Second Number")));
break;
}
case 5: {
System.out.println(
"Answer: " + random(getOperand("Enter first number"), getOperand("Enter Second Number")));
}
}
} while (userInput != 6);
}
}

output:--

Menu 1. Add 2. Subtract 3. Multiply 4. Divide 5. Generate Random Number 6. Quit Please select a number between 1-6 Enter firs

Add a comment
Know the answer?
Add Answer to:
This material is somewhat more theoretical than that of previous topics, so instead of writing a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What this Assignment Is About: Review on Java I topics, such as primitive data types, basic...

    What this Assignment Is About: Review on Java I topics, such as primitive data types, basic I/O, conditional and logical expressions, etc. Review on Java loops. Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are...

  • Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion,...

    Assighment. Creaung Java Classes with methods Note: If you have not yet completed this unit's Discussion, it is best to complete it before you begin this Assignment As studied in the Discussion, it is important to design a test plan prior to creating a class, as it will help reduce coding problems. In this unit's Assignment, you create, compile, and execute a class containing methods. Be sure to use best coding practices, such as creating a test plan, before you...

  • /* * Returns the redness score of this image. * The redness score is defined by...

    /* * Returns the redness score of this image. * The redness score is defined by the total number of pixels that have * a red value that is greater than both the blue and green * pixels divided by the total number of pixels */ public double redness() { // WRITE YOUR CODE HERE }In this part of the projectyou wll create a Class representing the extension of a Picture. To accomplish this, you will use a class calfed...

  • CIST 2371 Introduction to Java Unit 04 Lab Due Date: ________ Create a folder called Unit04...

    CIST 2371 Introduction to Java Unit 04 Lab Due Date: ________ Create a folder called Unit04 and put all your source files in this folder. You will create a UML diagram and two Java class files and that implements the classes in the UML diagram. Diagram Create a UML diagram that shows an Account class and an AccountTester class. The Account class holds the following data as Strings: account Number, type of account, card number and expire date. Include getter...

  • Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class...

    Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class •Initializing Objects using Constructors •Software Engineering with Private Instances Variables and Public Set/Get Methods •Uses Methods inside classes Description: You are asked to write a program to process two students’ scores. Each student will have scores for 3 tests, the user will input each student’s full name followed by their three scores. When the data for the two students are read from the keyboard,...

  • CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As...

    CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As needed Recursion OBJECTIVES Understand linked lists and sorting concepts and the syntax specific to implementing those concepts in Java. PROJECT The final objective of this project is to create a multi-player card game, but you will create your classes in the order given, as specified. (Analogy: you must have a solid foundation before you can build a house). In order to allow creative freedom,...

  • Y. Daniel Liang’s 8 Class Design Guidelines were posted on the File Manager and handed out...

    Y. Daniel Liang’s 8 Class Design Guidelines were posted on the File Manager and handed out in class. Please choose 5 guidelines and discuss them in depth. For each guideline, use 1 page or more for your discussion. You can use the code provided in class to demonstrate your points. The code should not be more than one-third of your writing. 1. Cohesion • [✓] A class should describe a single entity, and all the class operations should logically fit...

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • 1 More Than You Ever Wanted to Know About Pentagons Your assignment here is to create...

    1 More Than You Ever Wanted to Know About Pentagons Your assignment here is to create a Pentagon class to represent a regular Pentagon, which has five sides and all angles are of equal length. You will need to create the instance variables, constructors, and instance methods for the Pentagon. 1.1 Instance Methods There is only one thing that distinguishes any regular pentagon from another how big its sides are. Create an instance variable called size to represent the size...

  • CIST 1305 Unit 06 Drop Box Assignment General Instructions You will create a word processing document...

    CIST 1305 Unit 06 Drop Box Assignment General Instructions You will create a word processing document and save it in "PDF" format. If you turn your document in using the wrong format, you will get no credit for it. ONLY ONE FILE may be turned in for the assignment. If you make a mistake and need to turn in your work again, you may do so. I will only grade the latest file you turn in. The older ones will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT