• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Java simple class output

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make my program print out the following:
CPU 1: This CPU is 1th generation i3 (2.93GHz), launched: Q1'10 with price: 117.00 USD. SGX is not supported.
CPU 2: This CPU is 10th generation i9 (3.1GHz), launched: Q2'19 with price: 449.00 USD. SGX is supported.
CPU 1 Series: i3
CPU 1 Suggested price: 117.00 USD
CPU 1 Suggested price (after mutator call): 110.00 USD
Are CPU 1 and CPU 2 equal? NO
Is CPU 1 of higher generation than CPU 2? NO
CPU 1 Price at Q3'19 :26.40 USD
CPU 2 Price at Q3'19 :440.02 USD
But the parts that are in emphasis don't print out the same way in my code, and I have the error message:


I know that to use the quarter year as a condition, I need to convert a string into an int(so use Integer.parsInt()) and use String.split(), I don't know where to put the split and I don't know if I converted my strings correctly

 
 
Rancher
Posts: 144
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exceptions says that "Q3'19" is not a valid representation for a number.
Why you even want to convert it into a number in the first place? You deal with a point in time - wich is commonly known as a date - so converting it into a date might be a better solution.
 
Jennifer Osorio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its because for the code you see, in my assignment, it was written that I had to create a public method called priceNow(String sQuarterYear) that returns the estimated price of the CPU based on the supplied sQuarterYear variable (which is "Q1'10"). In each quarter after launch, the suggested price is reduced by 2%. The returned price cannot be under 0.0USD. If the supplied quarter/year in sQuarterYear is before the launch date of the CPU, there is no depreciation and the suggested price is returned
 
Marshal
Posts: 76432
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think you are going to have to divide that input “Q4'19” into parts, viz. 4 and 19. Find out about String#split() and Scanner#findInLine(), which might be useful to find your numbers. Both methods need a regular expression; It will probably be easier to find a regular expression to suit the Scanner method. I think I oughn't to give you more information than that, but you can probably work out something from the link I gave you. You are very dependent on the input being in a particular form, otherwise your method won't work.

Plese be careful about variable names. Start all variableNames and methodNames with lowerCaseLetters and use upperCase to mark new words. Don't start with UpperCaseLetters, don't_use_underscores and don't use prefixes to denote the type. You have a variable QuarterYear and a parameter sQuarterYear; that is a sure‑fire recipe for confusion.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic