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

java program Complete the following using Java Programming Create a switch state

ID: 3681865 • Letter: J

Question

java program

Complete the following using Java Programming Create a switch statement inside a for loop that tries each case and prints a message. Put a break after each case and test it, then see what happens when you remove the breaks. (Note: There are two parts to this code, one with break and other without. Create two methods or two different for loop with and without break statement. Create a class called Dog with an overloaded barko method Your method should be overloaded based on various primitive data types. and should print different types of barking howling, etc., depending on which overloaded version is called. Write a main0 that calls all the different versions. Create an enum of the six lowest denominations of paper currency. Write a switch statement for the enum. For each case, output a description of that particular curTency. Code needs to iterate over each enum value and get its descriptions using switch statement

Explanation / Answer

1). What i understood from queation, I coded. Please let me know in case of any modification.

public class SwitchTest {

   public static void main(String[] args) {
      
      
       // switch statement without bracket
       System.out.println("Switch without bracket around case");
       for(int i=1; i<=5; i++){
          
           switch (i) {
           case 1:
               System.out.println("Case 1");
          
           case 2:
               System.out.println("Case 2");
          
           case 3:
               System.out.println("Case 3");
          
           case 4:
               System.out.println("Case 4");
          
           case 5:
               System.out.println("Case 5");
          
           default:
               break;
           }
       }
      
       System.out.println(" Switch with bracket around case");
       for(int i=1; i<=5; i++){
          
           switch (i) {
           case 1:{
               System.out.println("Case 1");
           }
           case 2:{
               System.out.println("Case 2");
           }
           case 3:{
               System.out.println("Case 3");
           }
           case 4:{
               System.out.println("Case 4");
           }
           case 5:{
               System.out.println("Case 5");
           }
           default:
               break;
           }
       }
   }
}

2).

public class Dog {

   // bark n number of times
   public void bark(String str, int n){
       for(int i=1; i<=n; i++)
           System.out.println(str);
   }
  
   // bark one times
   public void bark(String str){
       System.out.println(str);
   }
  
   public static void main(String[] args) {
      
       Dog d = new Dog();
      
       d.bark("bhobho");
       d.bark("huahua", 5);
   }
}

3).

public enum Currency {
   Penny("1 Cent"),
Nickel("5 Cent "),
Dime("10 Cent "),
   Quarter("25 Cent "),
   Half("50 Cent "),
   Dollar("100 Cent ");
  
   private final String currency;

   Currency(String currency) {
   this.currency = currency;
   }
   public String getCurrentValue() {
return currency;
}
  
   public static void main(String[] args) {
      
       for(Currency c: Currency.values()){
          
           switch(c){
           case Penny:
               System.out.println(Penny.getCurrentValue());
               break;
           case Dime:
               System.out.println(Dime.getCurrentValue());
               break;
           case Nickel:
               System.out.println(Nickel.getCurrentValue());
               break;
           case Quarter:
               System.out.println(Quarter.getCurrentValue());
               break;
           case Half:
               System.out.println(Half.getCurrentValue());
               break;
           case Dollar:
               System.out.println(Dollar.getCurrentValue());
               break;
           }
       }
   }
}