Question

Take your code from Assignmnet#4 Task 1 and Task 2

All information about the question (Task 1 and task 2) are down below

Programming Assignments

Task 1 –

Page 39. in Programming A Comprehensive Introduction

Update your program from Assignment 2, Task #2

Allow the user to input their weight for the earth weight to moon weight conversion problem. Add an ifstatement that prompts the user if she inputs 0 or a negative number for her earth weight.

#13. Mars’ gravity is about 17 percent less that of the earth’s. (Meaning you weigh less on the moon). Write a program that computes your affective weight on Mars.

P9. 29 in book

2nd Task: Write a simple program displaying knowledge of if conditional statements and using the Scanner input method.

Create 2 input integer (int) variables. The input numbers should not be set by the programmer but entered by the user.

Have 2 simple equations that solve for a the variable ( c ).      c = a – b    and    c = b – a

Create statements for if (c) is a negative or non-negative number for each equation.

Display the possible outputs for in each equation.

Please enter an integer:               //Prompt the user

7                                  // Integer entered by the user not by the programmer.

Please enter an integer:               //Prompt the user

9                                  // Integer entered by the user not by the programmer.

a = 7                           // display the value of a

b = 9                                       // display the value of b

a is less than b                    // display the difference the relationship between and b

// Create space between each output

c = a – b                              

c = -2

c is negative             //create a statement stating whether c is negative or positive.

c = b - a

c = 2

c is non-negative

Expert Answer

AnonymousAnonymous answered this

Was this answer helpful?

0

0

If Else Ladder Example and Scanner Class Demo.

Scanner is a class which is used to read the input from the keyboard. Here we read the value of n from the keyboard and display the result using if else ladder.

import java.io.*;

import java.util.*;

public class IfElseIfLadder

{

public static void main(String args[])

{

int n;

System.out.println( " Enter the value of n- n=1 Hello, n=2 Hi, n=3 Good else No Match Found");

Scanner s =new Scanner(System.in); // read the value of n using the keyboard

n=s.nextInt();

if(n==1)

{

//This block will be executed only if "n" is equal to 1

System.out.println("Hello");

}

else if(n==2)

{

//This block will be executed only if "n" is equal to 2

System.out.println("Hi");

}

else if(n==3)

{

//This block will be executed only if "n" is equal to 3

System.out.println("Good");

}

else

{

System.out.println("No Match Found");

}

}

}

Output:

Enter the value of n- n=1 Hello, n=2 Hi, n=3 Good else No Match Found

3

Good.

program displaying knowledge of if conditional statements and using the Scanner input method.

import java.io.*;

import java.util.*;

public class Scanner_Demo

{

public static void main(String args[])

{

int a,b,c;

System.out.println(" Enter the values a and b");

Scanner s = new Scanner(System.in);

a=s.nextInt();

b=s.nextInt();

System.out.println(" Value of a is : " +a);

  System.out.println(" Value of b is : " +b);

if (a<b)

  System.out.println(" a is less than b");

else

System.out.println(" a is greater than b");

c=a-b;

System.out.println(" Value of c=a-b is : "+ c);

if(c>0)

  System.out.println(" Value of c is positive");

else

System.out.println(" Value of c is negative");

}

}

Output:

Enter the values a and b 3 1

Value of a is 3

Value of b is 1

a is greater than b

Value of c=a-b is 2

C is positive

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

Answer

import java.util.*;
import java.util.Scanner;
class Codechef
{
int seconds,minutes,hours;
Codechef()
{
seconds=0;
minutes=0;
hours=0;
}
public static void main (String[] args) throws java.lang.Exception
   {
   int n;
   Scanner s =new Scanner(System.in);
   System.out.println("Enter Seconds : ");
   n=s.nextInt();
   Codechef obj=new Codechef();
   obj.convertToMinutes(n);
   obj.convertToHMS(n);
   }
   void convertToMinutes(int s)
   {
   System.out.println("---------------CONVERSION TO MINUTES----------------");
   System.out.println("Seconds before Conversion : "+s);
   minutes=s/60;
   seconds=s%60;
   System.out.println("Minutes after Conversion : "+minutes);
   System.out.println("Seconds after Conversion : "+seconds);
   }
   void convertToHMS(int s)
   {
   System.out.println("---------------CONVERSION TO HOUR-MINUTES-SECONDS----------------");
   System.out.println("Seconds before Conversion : "+s);
   minutes=s/60;
   hours=minutes/60;
   minutes=minutes%60;
   seconds=s%60;
   System.out.println("Hours after Conversion : "+hours);
   System.out.println("Minutes after Conversion : "+minutes);
   System.out.println("Seconds after Conversion : "+seconds);
   }
}

OUTPUT

Console View Applet View Log View Enter Seconds 3661 CONVERSION TO MINUTES---- Seconds before Conversion 3661 Minutes after C

Console View Applet View Log View Enter Seconds 111 CONVERSION TO MINUTES---- Seconds before Conversion 111 Minutes after Con

Add a comment
Know the answer?
Add Answer to:
All information about the question (Task 1 and task 2) are down below Programming Assignments Task...
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
  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables...

    import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables int creditScore; double loanAmount,interestRate,interestAmount; final double I_a = 5.56,I_b = 6.38,I_c = 7.12,I_d = 9.34,I_e = 12.45,I_f = 0; String instructions = "This program calculates annual interest\n"+"based on a credit score.\n\n"; String output; Scanner input = new Scanner(System.in);// for receiving input from keyboard // get input from user System.out.println(instructions ); System.out.println("Enter the loan amount: $"); loanAmount = input.nextDouble(); System.out.println("Enter the credit score: "); creditScore...

  • Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs...

    Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs the user’s choice of the following functions the program exits should also be a user’s choice. Menu Item 1: Fibonacci number iterator, here you are to define an iterator class named FibonacciIterator for iterating Fibonacci numbers. The constructor takes an argument that specifies the limit of the maximum Fibonacci number. For example, prompt the user for size, use the size to call FibonacciIterator(“user input”)...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • Below is a java program that inputs an integer grade and turns it into a letter...

    Below is a java program that inputs an integer grade and turns it into a letter grade. Update the below java code as follows and comment each line to explain what is happening: 1. Convert the if-else-if code block to a switch statement to solve the problem. 2. Use modulus to convert the grade input so that the range of grades are converted to one value. (comment the line) import java.util.Scanner; public class GradeLetterTest { public static void main(String[] args)...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

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