Easy Java Programing. Take about five minutes if you know what you are doing. #2

profilejardsh
java_programming.pdf

1    

ITP  109:  Introduction  to  Java  Programming   Assignment  4    

Goal   In  this  assignment  you  will  program  a  Math  Equation  Program  and  practice  using…  

• The  Scanner  class  for  user  input   • Math  equations  in  Java   • If-­‐else  and  switch  statements   • Code  comments    

Requirements   Your  program  will  offer  the  user  several  options  to  choose  from,  and  once  they  have  selected  one,  it  will  perform  the   necessary  operations.  

• Create  your  program  using  Eclipse.  Name  your  project  Assignment4  and  the  Java  class  MathEquations.   • Use  the  Scanner  class  to  get  input  from  the  user  and  use  System.out  to  print  to  the  console  window.   • Use  a  switch  statement  once  the  user  has  entered  their  desired  calculation.   • Be  sure  to  comment  your  code.    

  • Choice  1:  Temperature  Converter  

o Prompt  the  user  to  enter  a  temperature.  You  will  need  to  store  it  in  a  variable  of  type  double.     o Prompt  the  user  to  enter  either  a  C  (or  c)  for  Celsius  or  an  F  (or  f)  for  Fahrenheit.         o Convert  the  temperature.  You  will  need  another  variable  to  hold  this  converted  temperature.  Use  if-­‐else  

statements  and  the  String  method  equalsIgnoreCase.   o If  Celsius  is  entered  convert  the  temperature  to  Fahrenheit  using  the  following  formula  

(pseudocode):   o convertedTemp  =  (9  (tempC)  /  5)  +  32  

o If  Fahrenheit  is  entered,  convert  the  temperature  to  Celsius  using  the  following  formula:     o convertedTemp  =  5  (tempF  –  32)  /  9  

o When  prompting  for  the  units  if  the  user  enters  anything  other  than  C,  c,  F,  or  f  print  an  error  message.   o Display  the  result  in  a  readable  format.  

• Choice  2:  Average  3  numbers   o Prompt  the  user  to  enter  three  different  numbers.  You  will  need  to  store  them  in  variables  of  type  double.     o Average  the  three  numbers  (add  them  together  and  divide  by  3),  and  store  the  average  in  another  variable.   o Display  the  three  numbers  and  their  average  in  a  readable  format.  

• Choice  3:  Greater  than,  less  than,  or  approximately  equal  to.   o Prompt  the  user  to  enter  two  different  numbers.  You  will  need  to  store  them  in  variables  of  type  double.     o Remembering  that  doubles  can’t  be  compared  to  be  exactly  equal,  but  that  you  need  to  check  within  a  

tolerance  (in  this  case,  use  a  tolerance  of  .01),  decide  if  the  first  number  entered  is  greater  than,  less  than,   or  approximately  equal  to  the  second  number  and  display  a  message  back  to  the  user.  

2    

Sample  output   Example  #1  

 

Example  #2  

 

Example  #3  

 

Example  #4  

 

Deliverables   1. A  compressed  Assignment4  folder  containing  a  file  named  MathEquations.  It  must  be  submitted  through  

Blackboard.   Here  are  the  instructions  for  submission   a) Navigate  to  your  project  folder.      

3    

b) Create  a  compressed  folder  with  all  your  code  (include  the  src  folder—if  you  don’t  have  a  src  folder,  make   sure  you  include  all  your  .java  files  that  are  within  the  project  folder).  

c) Name  the  folder  as  follows   ITP109_assignment#_lastname_firstname                      (replace  #  with  this  assignment  number)  

d) Upload  zip  file  to  Blackboard  site  for  our  course    

Grading   Item   Points   Switch  logic   5   Temperature  input   3   Temperature  conversion   5   Temperature  display  result   3   Average  input   3   Average  calculation   5   Average  display  result   3   Comparison  input   3   Comparison  calculation   5   Comparison  display  result   3   Comments,  style,  and  proper  submission   5   Total   43