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.
JAVA GUI AND OOP Overview: Java Swing is a lightweight Graphical User Interface (GUI) toolkit that includes a rich set of widgets. It includes package lets you make GUI components for your Java applications, and it is platform independent. In this activity, students will have an opportunity to design a GUI of a simple java program. Instruction: Create a program that would compute for the total amount of purchase based on user preferences. Design the user interface and the source code using object-oriented programming Requirements Design the user interface of the Pizza Ordering System. Sample interface design shown below (Design your own interface but use the same tools for every section) Pizza Ordering System Date July 05. 2019 Customer Available Pizza Mountain Pizza Regular Personal O Family O Pasta Spaghetti w/ Meatballs Supreme O Meat Lovers Special Pansit Bihon Pansit Palabok O Veggie Lovers Hawaiian Sotanghon Bacon Lovers 0 Drinks Glass/Mug Pitcher Crust type Thick Additional Cheese Beef Bacon O Drum Governor Pack Road, Baguio City Contact Number: 442-3316 Thin Details Compute Total Amount Amount Due: $643.50 Discount. $0.00 Tax (22%): $181 50 Close Application Pungratumer g: Diar Terrirgar , Total Amount $825.00 Compute the total amount that the customer will pay based on the following Price List: Pizza Supreme Meat Lovers Veggie Lovers Hawaiian Bacon Lovers Personal P 350 P 300 P 250 P 275 P 275 Regular P 550 P 500 P 450 P 400 P 400 Family P 1,000 P 850 P 600 P 750 P 800 If the customer orders Family Supreme pizza, the pizza would cost P1,000.00. If the customer orders another pizza, let say Regular Hawaiian pizza, add P400 to the cost. The total amount would be P1,400.00. Also, include in the total amount the additional orders (see table below) the customer might avail. Additional Order: Food Spaghetti with Meat ball P 95 Special Pansit Bihon P 50 Pansit Palabok P 75 Sotanghon P 60 Soft drinks in: Glass/Mug P 25 Picher P 65 Р 120 Additional: Cheese P100.00 Beef 250.00 Bacon 200.00 Dum In the details area, compute for the amount due which is 78% of the computed total amount, and the Tax which is 22% of computed the total amount. Source code must be in OOP style. Create classes of each type of pizza. In each class, encapsulate the prize by creating a private attribute. Use setter and getter method to pass the prize value to main class which is your interface (JFrame). You may use a simple conditional statement for additional orders and no need for a separate class. A practice activity is given as your guide. PRACTICE ACTIVITY: 1. Create a project Pizza and add a JFrame form. 2. Create a sub class of Pizza named Supreme. 3. Add a radiobutton, label and a button By default the names of the tools are as follows JRadioButton1 , JLabell and JButton1 4. Add the following code to Supreme class (Let's say prize = 280) package pizza; public class Supreme Pizza extends PizzaJFrame { private int prize; public void setPrize ) { this.prize= 280; } public int getPrize() { return prize; } 5. Go to your JFrame Form and double click JButtonl and add following code 85 Ç 86 87 88 89 private void jButtonlActionPerformed (java.awt.event. ActionEvent evt) if (RadioButtonl.isSelected()) { Supreme Pizza pl = new Supreme Pizza (); pl.set Prize(); jLabel1.setText (Integer.toString(pl.getPrize())); }else{ JOptionPane.showMessageDialog(this, "Other Pizza Type"); } 90 91 92 93 Note: The codes shaded in gray is automatically added by netbeans. NO NEED TO ADD ANOTHER ONE. Just add the if block. 6. Test the program. Click the button while the radio button is unchecked. A message box will appear. Test it again this time check radio button and click the button. The labell must display 280.