Write a Java method to check whether a string is a valid password. Each character must be stored in a character array
Password rules:
A password must have at least ten characters.
A password consists of only letters and digits.
A password must contain at least two digits.
Expected Output:
Input a password (You are agreeing to the above Terms and Conditions.): abcd1234 Password is valid: abcd1234
OOP Activity
1.
Create a class CIRCUIT with the following public attributes: total resistance, total voltage and total current. Assign proper variable type and name for each attribute. Total voltage must be static. (static double variablename)
2.
Create a method setVoltageSource() of circuit class to set a constant value of voltage to 24 volts. This value is true to all types of connection thus; it should be a static method.
3.
Create a public method getTotalCurrent() to compute and display total current in 2 decimal values.
Total current is equal to the ratio of voltage and total resistance. (I = V/R)
4.
Create a child class of class CIRCUITS named Series and Parallel
5.
Each class must have an integer attribute named numres. This variable holds the number of resistors in a circuit and will be used for display only.
6.
In series class, create a public method named computeTotalresistance(double r1, double r2). This method is used to accept two resistance values and computes the total resistance of a series connection with 2 resistors.
Total resistance is the summation of the two resistance values. Also, it sets numres equal to 2.
NOTE: store computed total resistance to the total resistance attribute of the parent class. A child class can use attributes and methods of a parent class
(Inheritance).
7.
Overload the method from the previous item (7) that accepts 3 resistance values and computes the total resistance of a series connection with 3 resistors. Total resistance is the summation of the three resistance values. Also, it sets numres equal to 3.
NOTE: store computed total resistance to the total resistance attribute of the parent class. A child class can use attributes and methods of a parent class
(Inheritance).
8.
Perform item 7 and 8 in parallel class.
a. Total resistance 2 resistor = 1/(1/resistor1 + 1/resistor2)
b. Total resistance 3 resistor = 1/(1/resistor1 + 1/resistor2 + 1/resistor3)
Set value of numres accordingly.
9.
Add new public methods in each class (series and parallel) named disType() to display the type of circuit connection and number of resistor (numres). See test case below.
10.
Implement encapsulation by setting up the total resistance attribute in both series and parallel class to private and creating public class to allow other class to access the total resistance value. This is an example of a read only function when using encapsulation.
11.
Create an interface class called DisplayCircuitType. It contains an abstract method of disType(). Modify the series class and parallel class to implement this interface class. A subclass (extends) can be also implement interface (implements). Syntax: public class childclassname extends parentclassname implements interfaceclassname
12.
Complete the program with the following steps:
a.
Use scanner to enter 3 values (resistor values). Create 3 variables to store each inputs
b.
Create 2 objects of Series Class and 2 objects of Parallel Class
c.
Call setvoltage() to set uniform voltage
d.
Work on with the first object of Series class with 2 resistors. Call computeTotalResistance and disType methods. Print the value of getTotalResistance. Call getTotalCurrent.
Note: In calling computeTotalResistance method you have to indicate number of parameters.
e.
Work on with the first object of Series class with 2 resistors. Call computeTotalResistance and disType methods. Print the value of getTotalResistance. Call getTotalCurrent.
Note: In calling computeTotalResistance method you have to indicate number of parameters.
f.
Test the program for the first circuit. If it gives the correct answer, work on the other circuits
.
Create a public method getTotalCurrent() to compute and display total current in 2 decimal values.
Total current is equal to the ratio of voltage and total resistance. (I = V/R)
Create a class CIRCUIT with the following public attributes: total resistance, total voltage and total current. Assign proper variable type and name for each attribute. Total voltage must be static. (static double variablename)
public class CIRCUIT {
private double totalResistance;
static int totalVoltage;
double totalCurrent;
public static void setVoltageSource() {
totalVoltage = 24;
}
public String getTotalCurrent() {
totalCurrent = totalVoltage / totalResistance;
return String.format("%.2f", totalCurrent);
}
/**
* @return the totalResistance
*/
public String getTotalResistance() {
return String.format("%.2f", totalResistance);
}
/**
* @param totalResistance the totalResistance to set
*/
public void setTotalResistance(double totalResistance) {
this.totalResistance = totalResistance;
}
}
***************************************************Series.java***********************************************************
public class Series extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(r1 + r2);
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(r1 + r2 + r3);
}
public void disType() {
System.out.println("SERIES CONNECTION with " + numres + " Resistors");
}
}
***************************************************Parallel.java***********************************************************
public class Parallel extends CIRCUIT implements DisplayCircuitType {
private int numres;
public void computeTotalResistance(double r1, double r2) {
numres = 2;
setTotalResistance(1 / ((1 / r1) + (1 / r2)));
}
public void computeTotalResistance(double r1, double r2, double r3) {
numres = 3;
setTotalResistance(1 / ((1 / r1) + (1 / r2) + (1 / r3)));
}
public void disType() {
System.out.println("PARALLEL CONNECTION with " + numres + " Resistors");
}
}
***************************************************DisplayCircuitType.java************************************************
public interface DisplayCircuitType {
void disType();
}
***************************************************Driver.java***********************************************************
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please Enter 3 resistance values: ");
double r1, r2, r3;
r1 = sc.nextDouble();
r2 = sc.nextDouble();
r3 = sc.nextDouble();
Series s1 = new Series();
Series s2 = new Series();
Parallel p1 = new Parallel();
Parallel p2 = new Parallel();
CIRCUIT.setVoltageSource();
s1.computeTotalResistance(r1, r2);
s1.disType();
System.out.println("Total Resistance in 24 (V) : " + s1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
s2.computeTotalResistance(r1, r2, r3);
s2.disType();
System.out.println("Total Resistance in 24 (V) : " + s2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + s2.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p1.computeTotalResistance(r1, r2);
p1.disType();
System.out.println("Total Resistance in 24 (V) : " + p1.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p1.getTotalCurrent());
System.out.println(" -----------------------------------------------");
p2.computeTotalResistance(r1, r2, r3);
p2.disType();
System.out.println("Total Resistance in 24 (V) : " + p2.getTotalResistance());
System.out.println("Total Current in 24 (V) : " + p2.getTotalCurrent());
sc.close();
}
}
WHAT IS THE ERROR IN THE PROGRAM? KINDLY FIX IT. I NEED IT ALREADY. TYSM
Create a sample program using try, catch and finally if the user will input incorrect value (user can enter number, string character, etc...) -
short line of code only
Book Management System
The project will manage record of books in stock in a file called books.txt. For each book in stock, Id, Name, Category, Author, Editor, Price, in stock and total sold are stored. These books can be updated and deleted with purchase and sell of stock.
The software should be able to find a book with id, name and quantity as well.
Write a Java method to check whether a string is a valid password. Each character must be stored in a character array
Password rules:
A password must have at least ten characters.
A password consists of only letters and digits.
A password must contain at least two digits.
Expected Output:
Input a password (You are agreeing to the above Terms and Conditions.): abcd1234
Password is valid: abcd1234
1. Create a class CIRCUIT with the following public attributes: total resistance, total voltage and total current. Assign proper variable type and name for each attribute. Total voltage must be static. (static double variablename)
2. Create a method setVoltageSource() of circuit class to set a constant value of voltage to 24 volts. This value is true to all types of connection thus; it should be a static method.
3. Create a public method getTotalCurrent() to compute and display total current in 2 decimal values. Total current is equal to the ratio of voltage and total resistance. (I = V/R)
4. Create a child class of class CIRCUITS named Series and Parallel
5. Each class must have an integer attribute named numres. This variable holds the number of resistors in a circuit and will be used for display only.
6. In series class, create a public method named computeTotalresistance(double r1, double r2). This method is used to accept two resistance values and computes the total resistance of a series connection with 2 resistors.
Total resistance is the summation of the two resistance values. Also, it sets numres equal to 2.
NOTE: store computed total resistance to the total resistance attribute of the parent class. A child class can use attributes and methods of a parent class (Inheritance).
7. Overload the method from the previous item (7) that accepts 3 resistance values and computes the total resistance of a series connection with 3 resistors. Total resistance is the summation of the three resistance values. Also, it sets numres equal to 3.
NOTE: store computed total resistance to the total resistance attribute of the parent class. A child class can use attributes and methods of a parent class (Inheritance).
8. Perform item 7 and 8 in parallel class.
a. Total resistance 2 resistor = 1/(1/resistor1 + 1/resistor2)
b. Total resistance 3 resistor = 1/(1/resistor1 + 1/resistor2 + 1/resistor3)
Set value of numres accordingly.
9. Add new public methods in each class (series and parallel) named disType() to display the type of circuit connection and number of resistor (numres). See test case below.
10. Implement encapsulation by setting up the total resistance attribute in both series and parallel class to private and creating public class to allow other class to access the total resistance value. This is an example of a read only function when using encapsulation.
11. Create an interface class called DisplayCircuitType. It contains an abstract method of disType(). Modify the series class and parallel class to implement this interface class. A subclass (extends) can be also implement interface (implements). Syntax: public class childclassname extends parentclassname implements interfaceclassname
12. Complete the program with the following steps:
a. Use scanner to enter 3 values (resistor values). Create 3 variables to store each inputs
b. Create 2 objects of Series Class and 2 objects of Parallel Class
c. Call setvoltage() to set uniform voltage
d. Work on with the first object of Series class with 2 resistors. Call
computeTotalResistance and disType methods. Print the value of
getTotalResistance. Call getTotalCurrent.
Note: In calling computeTotalResistance method you have to indicate number of parameters.
e. Work on with the first object of Series class with 2 resistors. Call
computeTotalResistance and disType methods. Print the value of
getTotalResistance. Call getTotalCurrent.
Note: In calling computeTotalResistance method you have to indicate number of parameters.
f. Test the program for the first circuit. If it gives the correct answer, work on the other circuits.
Create a java program that would compute and display the total mobile services fee incurred by a customer. Mobile services include text messages, calls in minutes and mobile data usage in megabytes.
Each customer was given a customer ID that would indicate the type of mobile plan he/she availed.
PLAN A:
-Customer ID ending with 0. Loyal member has 5 digits and above ID number.
-monthly fixed rate of P500.00
-allows free text messaging up to 250 messages. Beyond that, each message is charged 90 centavos.
-All-net calls up to 60 mins. Exceeding minutes applies P5/min.
-P5/MB. Free use of mobile data up to 80MB.
-20% discount from the total charge for Loyal member.
PLAN B:
-Customer ID ending with 5. Loyal member has 5 digits and above ID number.
-monthly fixed rate of P750.00
-allows free text messaging of up to 500 messages. Beyond that, each message is charged 70 centavos.
-All-net calls up to 120 mins. Exceeding minutes applies P5/min.
-P5/MB. Free use of mobile data up to 100MB.
-40% discount from the total charge.
PLAN C:
-Customer ID ending with 2. Loyal member has 5 digits and above ID number.
-monthly fixed rate of P1,200.00
-allows free text messaging of up to 1,000 messages. Beyond that, each message is charged 50 centavos.
-All-net calls up to 240 mins. Exceeding minutes applies P5/min.
-P5/MB. Free use of mobile data up to 500MB.
-60% discount from the total charge.
Input:
The first line of the input file will contain a single integer N that represents the
Customer ID number. Next line consists of 3 integer T, C and D, separated by commas (,). T is the total number of text messages; C is the total number of calls in minutes and D is the total data usage in MB.
Output:
The total mobile fee of the customer applying all charges given in the description and discounts if applicable. In addition, the program must also display an offer to upgrade the plan type for customers who have exceeded their monthly fixed rate by 200%.
Ex. Plan A
–Total bill of P1,860.00 means the customer exceeded by P1,360.00 or 272% from his/her monthly fixed rate of P500 (P1,860-500=1,360).