Question

ifelse2 Ward References Mailings Review ew Subtitle Title TNO ::E . 12 . .|TI Emphasis Heading i LNormal! Strong 18-y.A-l าร Styles Paragraph Unit Form Selection Exercises #2 Standards Focus: input/output,restrictive input, formatted output, logic, design, Boolean and logical operators, String class method usage 1. Our program will convert a weight expressed in pounds into kilograms a. Our input is the weight in pounds b. Our output is the weight in kilograms c. We also know that Kilograms Pounds /2.2 Lets take another look at the program which converts pounds to kilograms. Since a weight cannot be a negative number, our program should not accept a negative number as a valid weight. Lets rewrite th e program to print an error message if the weight entered in pounds is negative. 2. An Auto Insurance Program Example - Write a program to determine the cost of an automobile insurance premium, based on drivers age and the number of accidents that the driver has had. basic insurance charge is $500. There is a surcharge of $100 if the driver is under 25 and an additional surcharge for accidents: of 50 125 225 375 575 6 or moreNo insurance the user for a number and print good if the number is greater than 5 and between 8 & 10 (inclusive) or greater than 33. Otherwise, print bad. Use the logical operators in your if statement.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

WeightConverter.java

package classes9;

import java.util.Scanner;

public class WeightConverter {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter weight in pounds : ");

double weight = sc.nextDouble();

if(weight<0){

System.out.println("Invalid entry!!! Weight cannot be empty.");

}else{

double kilo = weight/2.2;

System.out.printf("Weight %.2f pounds equals to %.2f in kilograms",weight,kilo);

}

sc.close();

}

}

AutoInsurance.java

package classes9;

import java.util.Scanner;

public class AutoInsurance {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter your age : ");

double age = sc.nextDouble();

double basicCharge = 500;

if(age<25){

basicCharge+=100;

}

System.out.print("Enter number of accident : ");

int accidentCount = sc.nextInt();

if(accidentCount==1){

basicCharge+=50;

}else if(accidentCount==2){

basicCharge+=125;

}else if(accidentCount==3){

basicCharge+=225;

}else if(accidentCount==4){

basicCharge+=375;

}else if(accidentCount==5){

basicCharge+=575;

}else if(accidentCount>5){

System.out.println("Sorry you are not eligible for insurance");

return ;

}

System.out.println("Your insurance charge is : $"+basicCharge);

sc.close();

}

}

AmIgood.java

package classes9;

import java.util.Scanner;

public class AmIgood {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter a number : ");

int number = sc.nextInt();

if( ((number>5) &&(number>=8 && number<=10)) || number>33){

System.out.println("Good");

}else{

System.out.println("Bad");

}

sc.close();

}

}

output:

Add a comment
Know the answer?
Add Answer to:
ifelse2 Ward References Mailings Review ew Subtitle Title TNO ::E . 12 . .|TI Emphasis Heading...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT