Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

** Use Java Assingment#9 Answer#s: 2E and 5E Chapter 5 Exercises #2 - \"repeat E

ID: 3766938 • Letter: #

Question

** Use Java

Assingment#9

Answer#s: 2E and 5E
Chapter 5 Exercises

#2 - "repeat Exercise 1 for a credit card account ..."

#5 - "Consider a Java class that you could use to get an ..."

#1 Design a class to represent a credit card.
Think about the attributes of a credit card; that is,
what does is on the card? What behaviors might be reasonable
for credit card? Use the answers to these questions to write a UML class
diagram for a credit card class> these give three examples of
instances of this class.


#2E - "repeat Exercise 1 for a credit card account instead of a credit card.
An account represents the charges and payments made using a credit card.

#5E - "Consider a Java class that you could use to get an acceptable
integer value from the user. An object of this class will have the attributes

- Minimum accepted value
- Maximum accepted value
- Prompt string

and the following method:

- getValue displays the prompt and reads a value using the class Scanner.
If the value read is not the allowed range, the method should display an error message
and ask the user for a new value, repeating these actions until an acceptable value
is entered. The method then returns the value read.

a.) Write preconditions and postconditions for the method getValue.

b.) Implement the class in Java.

c.) Write some Java statements that test the class.

Comment

this is UML (This part is correct/ focus on the rest)

This should link should work :

https://s3.amazonaws.com/answer-board-image/8747887c-7b8b-453b-a768-f3d46b731963.jpeg

#2E

public class Creditcard
{
private String name;
private int accountNumber;
private int pin;
private double accountBalance;

public BankAccount(String n, int num,int p, double balance)
{
name=n;
accountNumber=num;
pin=p;
accountBalance=balance;
}

public String getName()
{
return name;
}

public void changeName(String n)
{
name=n;
}

public int getAccountNumber()
{
return accountNumber;
}

public void setAccountNumber(int account)
{
accountNumber=account;
}

public int getPin()
{
return pin;
}

public void setPin(int p)
{
pin=p;
}

public double getBalance()
{
return accountBalance;
}

public void setBalance(double balance)
{
accountBalance=balance;
}

public void addBalance(double adding)
{
accountBalance+=adding;
}

public void subtractBalance(double subtracting)
{
accountBalance-=subtracting;
}
}

#5E

Value::

import java.util.Scanner;

public class Value

{

      private int MinAcceptedValue;

      private int MaxAcceptedValue;

      private String output;

           

      public Value(int min,int max)

      {

            MinAcceptedValue=min;

            MaxAcceptedValue=max;

//Define Scanner

           

            Scanner keyboard=new Scanner(System.in);

           

            int n = keyboard.nextInt();

            System.out.println("Enter an integer variable: "+n);

            keyboard.close();

           

      }

public int getValue()

{     Scanner keyboard=new Scanner(System.in);

      System.out.println("Enter an integer value");

      int n=keyboard.nextInt();

      while(n<MinAcceptedValue && n>MaxAcceptedValue)

      {

            System.out.println("Error: given number not is in range: Try again");

            System.out.println("Enter an integer value");

            n=keyboard.nextInt();

      }

            return n;

      }

      public static void main(String[] args)

      {

     

      Value v=new Value(10,1000);

      v.getValue();

      System.out.println();

      }

}

Explanation / Answer

2E : please note you do not provide any information regarding calculatedebits, calculatecredits and calculatebalance methods about the logic. So I have commented those method after writing signature.


public class CreditCardAccount {

  
   private int cardno;
   private String name;
   private int accountNumber;
   //private int pin;
   private double creditLimit;
   private String exDate;
   int chargesCat;
   private double accountBalance;

   public CreditCardAccount(int no,String Name, int num,double CL,String date, int Charges,double balance)
   {
       cardno=no;
   name=Name;
   accountNumber=num;
   creditLimit=CL;
   exDate=date;
   chargesCat=Charges;
   accountBalance=balance;
   }
int getCreditAccountNumber()
{
   return accountNumber;
}
  
int getCardNumber()
{
   return cardno;
}
double getCreditLimit()
{
   return creditLimit;
}

String getExpiryDate()
{
   return exDate;
}

void setExpiryDate(String s)
{
   exDate=s;
}

int getChargesCategory()
{
   return chargesCat;
}

void setChargesCategory(int s)
{
   chargesCat=s;
}
double getBalance()
{
   return accountBalance;
}

void getBalance(double s)
{
   accountBalance=s;
}
String getCardHolderName()
{
   return name;
}
/*double calculateDebits(double s)
{
return ;  
}

double calculateCredits(double s)
{
return ;  
}*/  
  
/*double calculateBalance(double s)
{
  
}*/
  
  
public static void main(String[] args)
{
  
   CreditCardAccount c1= new CreditCardAccount(123457890,"Ron Deer",1234567,50000,"12/2015",5,50000);  
   CreditCardAccount c2= new CreditCardAccount(123457,"Ken Sowja",1234533,25000,"1/2016",4,25000);  
   CreditCardAccount c3= new CreditCardAccount(127890,"Yam Sow",4234523,60000,"1/2018",6,60000);  
System.out.println("cust1:CreditCardAccount");
System.out.println("cardAccountNumber="+c1.getCreditAccountNumber());
System.out.println("cardNumber="+c1.getCardNumber());
System.out.println("cardHolderName="+c1.getCardHolderName());
System.out.println("creditlimit="+c1.getCreditLimit());
System.out.println("expiryDate="+c1.getExpiryDate());
System.out.println("chagesCategory="+c1.getChargesCategory());
System.out.println("balance="+c1.getBalance());
System.out.println("");

System.out.println("cust2:CreditCardAccount");
System.out.println("cardAccountNumber="+c2.getCreditAccountNumber());
System.out.println("cardNumber="+c2.getCardNumber());
System.out.println("cardHolderName="+c2.getCardHolderName());
System.out.println("creditlimit="+c2.getCreditLimit());
System.out.println("expiryDate="+c2.getExpiryDate());
System.out.println("chagesCategory="+c2.getChargesCategory());
System.out.println("balance="+c2.getBalance());
System.out.println("");

System.out.println("cust3:CreditCardAccount");
System.out.println("cardAccountNumber="+c3.getCreditAccountNumber());
System.out.println("cardNumber="+c3.getCardNumber());
System.out.println("cardHolderName="+c3.getCardHolderName());
System.out.println("creditlimit="+c3.getCreditLimit());
System.out.println("expiryDate="+c3.getExpiryDate());
System.out.println("chagesCategory="+c3.getChargesCategory());
System.out.println("balance="+c3.getBalance());  
}
  
  
  
  
}

5E :

PreConditions for method is :

1. You should provide minimum and maximum limit to user so that he can enter no correctly.

2. As you provide Scanner in Constructor itself. There is no need of this there.

PostConditions:

1. Scanner should close after successful read

Code:

import java.util.Scanner;

public class Value

{

      private int MinAcceptedValue;

      private int MaxAcceptedValue;

      private String output;

      public Value(int min,int max)

      {

            MinAcceptedValue=min;

            MaxAcceptedValue=max;

         

      }

public int getValue()

{     Scanner keyboard=new Scanner(System.in);

      System.out.println("Enter an integer value");

      int n=keyboard.nextInt();

      while(n<MinAcceptedValue && n>MaxAcceptedValue)

      {

            System.out.println("Error: given number not is in range: Try again");

            System.out.println("Enter an integer value");

            n=keyboard.nextInt();

      }

     keyboard.close();

       return n;

      }

      public static void main(String[] args)

      {

     

      Value v=new Value(10,1000);

       System.out.println("The number Entered by user is "+ v.getValue());

      }

}