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

This question has 2 parts. 1a-b. Again, it\'s one question with 2 parts. All par

ID: 3606201 • Letter: T

Question

This question has 2 parts. 1a-b. Again, it's one question with 2 parts. All parts need to be answered correctly. You must: Comment and Format and Must make sure about indenting. If you don't follow these steps, it will be flagged for review.

This is on Dialog Boxes, loops and Strings- So make sure to use these methods.

Exercise 1a. The cost this year (2017) of a house is $125000. Each year the cost increases by 1.3%. write a Java program that asks you to type a number (say N) representing a time period in years. The program then prints the cost of the house yearly for N years starting in the current year (2017) to 2017-N. The program must use a while loop to compute and print the results. You need not concern yourself with the exact display of the decimal point. Test this program with two different numbers of vears. The program works as follows: Please type a number of years: 10 Year: 2017 - Cost $125000.0 Year: 2015 - Cost $123375.0 Year: 2007 - Cost xx Exercise 1b. Write a program to read two positive integer numbers and a multiplier. If the first number is smaller than the second number, then the program will write all numbers starting from the smallest number to the largest number times the multiplier (the numbers between the two numbers in increasing order). If the first number is larger than the second number, then the program will print all the numbers going from largest to the smallest times the multiplier (the numbers between the two numbers in decreasing order). If the two numbers are the same, then use a while loop to keep asking the user to enter two different numbers until the user inputs two different numbers. Test this program three times: once showing inputting a smaller than larger number, a larger followed by a smaller number and when the numbers are the same where it takes the user at least 3 times to get the numbers correct. Sample output Please type two numbers: 2 10 Please type a multiplier: 2 4 6 8 10 12 14 18 20 Please type two numbers: 50 12 Please type a multiplier: 5 250 245 240 60 Please type two numbers: 4 4 Error: the numbers must be different. Try Again. Please type two numbers: -5 -5 Error: the numbers must be positive and must be different. Try Again Please type two numbers: 1 4 Please type a multiplier: 10 10 20 30 40

Explanation / Answer

import java.util.Scanner;

class Main{
public static void main(String[] args)
{
// declaring variables
int n, year = 2017;
double val = 125000;
  
// taking user input of N
System.out.print("Please type a number of years: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
  
// printing first line
System.out.printf("Year: %d - Cost $%.1f ",year,val);
  
// using while loop to loop for n times
// decrementing year and n by 1 each time
// calculating amount for previous month and printing
while(n != 0)
{
year--;
val = val * (1 - (1.3/100));
System.out.printf("Year: %d - Cost $%.1f ",year,val);
n--;
}
}
}

/*
SAMPLE OUTPUT
Please type a number of years: 10
Year: 2017 - Cost $125000.0
Year: 2016 - Cost $123375.0
Year: 2015 - Cost $121771.1
Year: 2014 - Cost $120188.1
Year: 2013 - Cost $118625.7
Year: 2012 - Cost $117083.5
Year: 2011 - Cost $115561.4
Year: 2010 - Cost $114059.1
Year: 2009 - Cost $112576.4
Year: 2008 - Cost $111112.9
Year: 2007 - Cost $109668.4
*/

import java.util.Scanner;

class Main{
public static void main(String[] args)
{
// declaring variables
int a=0, b=0, mul;
Scanner sc = new Scanner(System.in);
  
// taking user input and validating
while(a == b || a<0 || b<0)
{
System.out.print("Please type two numbers: ");
a = sc.nextInt();
b = sc.nextInt();
if(a == b)
System.out.println("Error: The numbers must be different. Try Again. ");
else if(a<0 || b<0)
System.out.println("Error: The numbers must be positive and must be different. Try Again. ");
}
  
System.out.print("Pelase type a multiplier: ");
mul = sc.nextInt();
  
// for a greater than b
if(a>b)
for(int i=a; i>=b; i--)
System.out.print(i*mul+" ");
  
// for b greater than a
else
for(int i=a; i<=b; i++)
System.out.print(i*mul+" ");
}
}

/*SAMPLE OUTPUT

Please type two numbers: 2 10
Pelase type a multiplier: 2
4 6 8 10 12 14 16 18 20


Please type two numbers: 50 12
Pelase type a multiplier: 5
250 245 240 235 230 225 220 215 210 205 200 195 190 185 180 175 170 165 160 155 150 145 140 135 130 125 120 115 110 105 100 95 90 85 80 75 70 65 60


Please type two numbers: 4 4
Error: The numbers must be different. Try Again.

Please type two numbers: -5 -5
Error: The numbers must be different. Try Again.

Please type two numbers: 1 4
Pelase type a multiplier: 10
10 20 30 40
*/

import java.util.Scanner;

class Main{
public static void main(String[] args)
{
// declaring variables
int n, year = 2017;
double val = 125000;
  
// taking user input of N
System.out.print("Please type a number of years: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
  
// printing first line
System.out.printf("Year: %d - Cost $%.1f ",year,val);
  
// using while loop to loop for n times
// decrementing year and n by 1 each time
// calculating amount for previous month and printing
while(n != 0)
{
year--;
val = val * (1 - (1.3/100));
System.out.printf("Year: %d - Cost $%.1f ",year,val);
n--;
}
}
}

/*
SAMPLE OUTPUT
Please type a number of years: 10
Year: 2017 - Cost $125000.0
Year: 2016 - Cost $123375.0
Year: 2015 - Cost $121771.1
Year: 2014 - Cost $120188.1
Year: 2013 - Cost $118625.7
Year: 2012 - Cost $117083.5
Year: 2011 - Cost $115561.4
Year: 2010 - Cost $114059.1
Year: 2009 - Cost $112576.4
Year: 2008 - Cost $111112.9
Year: 2007 - Cost $109668.4
*/

import java.util.Scanner;

class Main{
public static void main(String[] args)
{
// declaring variables
int a=0, b=0, mul;
Scanner sc = new Scanner(System.in);
  
// taking user input and validating
while(a == b || a<0 || b<0)
{
System.out.print("Please type two numbers: ");
a = sc.nextInt();
b = sc.nextInt();
if(a == b)
System.out.println("Error: The numbers must be different. Try Again. ");
else if(a<0 || b<0)
System.out.println("Error: The numbers must be positive and must be different. Try Again. ");
}
  
System.out.print("Pelase type a multiplier: ");
mul = sc.nextInt();
  
// for a greater than b
if(a>b)
for(int i=a; i>=b; i--)
System.out.print(i*mul+" ");
  
// for b greater than a
else
for(int i=a; i<=b; i++)
System.out.print(i*mul+" ");
}
}

/*SAMPLE OUTPUT

Please type two numbers: 2 10
Pelase type a multiplier: 2
4 6 8 10 12 14 16 18 20


Please type two numbers: 50 12
Pelase type a multiplier: 5
250 245 240 235 230 225 220 215 210 205 200 195 190 185 180 175 170 165 160 155 150 145 140 135 130 125 120 115 110 105 100 95 90 85 80 75 70 65 60


Please type two numbers: 4 4
Error: The numbers must be different. Try Again.

Please type two numbers: -5 -5
Error: The numbers must be different. Try Again.

Please type two numbers: 1 4
Pelase type a multiplier: 10
10 20 30 40
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote