Answer to Question #268036 in Java | JSP | JSF for Candy

Question #268036

Write pseudo code that prints the smallest value among a list of numbers.


2. Write a subroutine named "printDayofWeek" that will output the day of the week for a given number. Use Swtich-case. For example, the command "1” would output “Sunday”.


3. The Car class (subclass) inherits the attributes and methods from the Vehicle class (superclass). And every car has model. Please also add toString method to the Car class to print out the brand, and model of the car.

Class Vehicle { protected String brand; Vehicle()

{

Brand = “Ford”; }

public void honk() { System.out.println("Tuut, tuut!");

} }

Please help write the Car class.


4. Try to refactor below codes for computing score (underlined part) with extract methods.

// Vehicle attribute

// Vehicle constructor

// Vehicle method

  public class Customer {

void foo() {

int a, b, c, xfactor;

int

}


1
Expert's answer
2021-11-24T00:43:35-0500

1..



public class Main
{
	public static void main(String[] args) {
		int [] list={5,6,3,8,4,2,7,1,9,10};
		int min=list[0];
		for(int i=0;i<list.length;i++){
		    if(list[i]<min){
		        min=list[i];
		    }
		}
		System.out.println("The smallest value among the numbers in the list is: "+min);
	}
}


2..

import java.util.Scanner;
public class Main
{
    static void printDayofWeek(int n){
        switch(n){
            case 1:
                System.out.println("Sunday");
                break;
            case 2:
                System.out.println("Monday");
                break;
            case 3:
                System.out.println("Tuesday");
                break;
            case 4:
                System.out.println("Wednesday");
                break;
            case 5:
                System.out.println("Thursday");
                break;
            case 6:
                System.out.println("Friday");
                break;
            case 7:
                System.out.println("Saturday");
                break;
            default:
                System.out.println("Invalid number");
                break;
        }
    }
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		System.out.print("Enter a number: ");
		int day=in.nextInt();
		printDayofWeek(day);
	}
}


3..

class Car extends Vehicle{
    private String model;
    
    public String toString(){
        return "Brand is "+brand+" and model is "+model;
    }
}


4..


 public class Customer {


    void foo() {
    
    int a, b, c, xfactor;
    
    }
    Customer(){
        
    }


}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS