Question

A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....

A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”.

B. Write a java program that creates the following two arrays:

String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”};

int[] votes = {7345,4324,3211};

Write the code that will search the votes array for the candidate with the largest number of votes and prints the name of that candidate.

Homework Answers

Answer #1

QUESTION (A):-

import java.util.Scanner;

public class Demo {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

System.out.println("enter"+"bus"+"or "+"Subway"+" or " +"walk ");

String str=sc.next();

if(str.equals("bus"))

System.out.println("$1.00");

else if(str.equals("subway"))

System.out.println("$1.50");

else if(str.equals("walk"))

System.out.println("Free");

}

}

QUESTION(B):-

public class MyClass {

public static void main(String args[]) {

String[] candidates = {"S Jones","Justin Fairfax","Clark Duncan"};

int[] votes = {7345,4324,3211};

int max=votes[0];

int index=0;

for(int i=0;i<3;i++)

{

if(max<votes[i])

{

max=votes[i];

index=i;

}

  

}

System.out.println("Name of the candidate is "+candidates[index]);

}

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
Write a program that allows the user to enter the last names of five candidates in...
Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by each candidate. The program should then output each candidate’s name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follows: Candidate Johnson Miller Duffy Robinson Sam Votes Received 5000 4000 6000 2500 1800 19300...
Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds)
DATA STRUCTURE /C++ Write a program that allows the user to enter the last names offive...
DATA STRUCTURE /C++ Write a program that allows the user to enter the last names offive candidates in a local election and the votes received by each candidate. The program should then output each candidate’s name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follows: Candidate Johnson Miller Duffy Robinson Sam Total Votes Received 5000 4000 6000...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.
Write Java program Lab51.java which takes in a string from the user, converts it to an...
Write Java program Lab51.java which takes in a string from the user, converts it to an array of characters (char[] word) and calls the method: public static int countVowels(char[]) which returns the number of vowels in word. (You have to write countVowels(char[]) ).
B.2. Write a Java program to display a dialog box that asks you to enter your...
B.2. Write a Java program to display a dialog box that asks you to enter your user name and the age as shown below: The program displays in a dialog box the sum of digits of your age. For example, if you age is 19, the sum will be 1+9 = 10 and the output will be as shown below: ( it just shows a message box that says the sum of the digits age of john is 10.
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT